X Tutup
Skip to content

Commit ad680df

Browse files
basrokLabz
authored andcommitted
Fix for inline constructors bug #12149 (#12169)
* Fix #12149 * Add unit test
1 parent c18460f commit ad680df

File tree

2 files changed

+68
-17
lines changed

2 files changed

+68
-17
lines changed

src/optimization/inlineConstructors.ml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -223,23 +223,26 @@ let inline_constructors ctx original_e =
223223
The id is incremented each time and is used later in the final_map phase to identify the correct inline_object.
224224
*)
225225
let rec mark_ctors ?(force_inline=false) e : texpr =
226-
let is_meta_inline = match e.eexpr with (TMeta((Meta.Inline,_,_),e)) -> true | _ -> false in
227-
let e = Type.map_expr (mark_ctors ~force_inline:is_meta_inline) e in
228-
let mark() =
229-
incr curr_io_id;
230-
let id_expr = (EConst(Int (string_of_int !curr_io_id, None)), e.epos) in
231-
let meta = (Meta.InlineObject, [id_expr], e.epos) in
232-
mk (TMeta(meta, e)) e.etype e.epos
233-
in
234-
match e.eexpr, force_inline with
235-
| TObjectDecl _, _
236-
| TArrayDecl _, _
237-
| TNew _, true ->
238-
mark()
239-
| TNew({ cl_constructor = Some ({cf_kind = Method MethInline; cf_expr = Some ({eexpr = TFunction _})} as cf)} as c,_,_), _ ->
240-
if needs_inline ctx (Some c) cf then mark()
241-
else e
242-
| _ -> e
226+
match e.eexpr with
227+
| TMeta((Meta.InlineConstructorArgument _,_,_),_) -> e
228+
| _ ->
229+
let is_meta_inline = match e.eexpr with (TMeta((Meta.Inline,_,_),e)) -> true | _ -> false in
230+
let e = Type.map_expr (mark_ctors ~force_inline:is_meta_inline) e in
231+
let mark() =
232+
incr curr_io_id;
233+
let id_expr = (EConst(Int (string_of_int !curr_io_id, None)), e.epos) in
234+
let meta = (Meta.InlineObject, [id_expr], e.epos) in
235+
mk (TMeta(meta, e)) e.etype e.epos
236+
in
237+
match e.eexpr, force_inline with
238+
| TObjectDecl _, _
239+
| TArrayDecl _, _
240+
| TNew _, true ->
241+
mark()
242+
| TNew({ cl_constructor = Some ({cf_kind = Method MethInline; cf_expr = Some ({eexpr = TFunction _})} as cf)} as c,_,_), _ ->
243+
if needs_inline ctx (Some c) cf then mark()
244+
else e
245+
| _ -> e
243246
in
244247

245248
(*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package unit.issues;
2+
3+
final class Vec {
4+
public var x:Float;
5+
6+
public inline function new(x:Float)
7+
this.x = x;
8+
}
9+
10+
final class Rect {
11+
public var top_left:Vec;
12+
13+
public inline function new(top_left:Vec)
14+
this.top_left = top_left;
15+
}
16+
17+
enum Shape {
18+
Vec(v:Vec);
19+
}
20+
21+
interface BodyInt {
22+
function shape():Shape;
23+
}
24+
25+
26+
class Body implements BodyInt {
27+
public inline function shape():Shape {
28+
throw new Rect(new Vec(1)).top_left;
29+
}
30+
}
31+
32+
class Issue12149 extends Test {
33+
function test() {
34+
noAssert();
35+
}
36+
37+
static inline function update_entity<T:BodyInt>(body:T) {
38+
switch body.shape() {
39+
case Vec(v):
40+
throw new Vec(new Vec(new Vec(v.x).x).x);
41+
default:
42+
throw "";
43+
}
44+
}
45+
46+
static function set_pos(body:Body)
47+
update_entity(body);
48+
}

0 commit comments

Comments
 (0)
X Tutup