2
0
Эх сурвалжийг харах

Fix fail to inline extern constructor not producing an error #6034 (#6035)

* Fix inline extern constructors failing to inline not producing an error #6034

* inline constructors bugix optimization:
Keep count of extern inline constructors and only do the third pass if the count is not 0.

* No third pass is needed, check in the second pass if there are extern inline constructors left.
basro 8 жил өмнө
parent
commit
c32e7d5825

+ 5 - 1
src/optimization/optimizer.ml

@@ -1222,6 +1222,7 @@ let inline_constructors ctx e =
 		if i < 0 then "n" ^ (string_of_int (-i))
 		else (string_of_int i)
 	in
+	let is_extern_ctor c cf = c.cl_extern || Meta.has Meta.Extern cf.cf_meta in
 	let rec find_locals e = match e.eexpr with
 		| TVar(v,Some e1) ->
 			find_locals e1;
@@ -1249,7 +1250,7 @@ let inline_constructors ctx e =
 							| [] -> e
 							| _ -> mk (TBlock (List.rev (e :: el_init))) e.etype e.epos
 						in
-						add v e' (IKCtor(cf,c.cl_extern || Meta.has Meta.Extern cf.cf_meta));
+						add v e' (IKCtor(cf,is_extern_ctor c cf));
 						find_locals e
 					| None ->
 						()
@@ -1399,6 +1400,9 @@ let inline_constructors ctx e =
 			in
 			let el = block [] el in
 			mk (TBlock (List.rev el)) e.etype e.epos
+		| TNew({ cl_constructor = Some ({cf_kind = Method MethInline; cf_expr = Some ({eexpr = TFunction _})} as cf)} as c,_,_) when is_extern_ctor c cf ->
+			display_error ctx "Extern constructor could not be inlined" e.epos;
+			Type.map_expr loop e
 		| _ ->
 			Type.map_expr loop e
 	in