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

Fix #6342 (#6345)

* Always unwrap blocks that return an inline object. Fixes #6324

* Test for issue #6324

* Change analyzer(ignore) into analyzer(no_optimize)
Mario Carbajal 8 жил өмнө
parent
commit
d87a0f1216

+ 1 - 1
src/optimization/inlineConstructors.ml

@@ -496,7 +496,7 @@ let inline_constructors ctx e =
 					loop (el'@acc) el
 			in
 			let el, io = loop [] el in
-			let el = if unwrap_block then el else [mk (TBlock (List.rev el)) e.etype e.epos] in
+			let el = if unwrap_block || Option.is_some io then el else [mk (TBlock (List.rev el)) e.etype e.epos] in
 			el, io
 		| TMeta((Meta.InlineConstructorArgument (_,io_id_start),_,_),e) ->
 			let old_io_id = !current_io_id in

+ 32 - 0
tests/unit/src/unit/issues/Issue6342.hx

@@ -0,0 +1,32 @@
+package unit.issues;
+
+class Issue6342 extends unit.Test {
+	@:analyzer(no_optimize)
+	function test() {
+		var t = new A(1);
+		var tmp1 = t.foo().x;
+		eq(1, tmp1);
+		
+		var tmp2 = ({
+			new A(2);
+		}).x;
+		eq(2, tmp2);
+	}
+}
+
+@:keep
+private class A
+{
+	public var x:Int;
+	
+	@:analyzer(no_optimize)
+	public inline function new(x) {
+		this.x = x;
+	}
+	
+	@:analyzer(no_optimize)
+	public inline function foo() {
+		var tmp = x;
+		return new A(x);
+	}
+}