浏览代码

Flatten blocks in inline constructors. Fixes #6229 (#6230)

* When unwrapping a block, also unwrap child blocks

* Test for #6229
Mario Carbajal 8 年之前
父节点
当前提交
1861c5579a
共有 2 个文件被更改,包括 29 次插入2 次删除
  1. 2 2
      src/optimization/inlineConstructors.ml
  2. 27 0
      tests/optimization/src/issues/Issue6229.hx

+ 2 - 2
src/optimization/inlineConstructors.ml

@@ -489,10 +489,10 @@ let inline_constructors ctx e =
 			let rec loop acc el = match el with
 				| [] -> acc, None
 				| [e] ->
-					let el',io = final_map e in
+					let el',io = final_map ~unwrap_block:unwrap_block e in
 					(el'@acc), io
 				| e::el ->
-					let el',_ = final_map e in
+					let el',_ = final_map ~unwrap_block:unwrap_block e in
 					loop (el'@acc) el
 			in
 			let el, io = loop [] el in

+ 27 - 0
tests/optimization/src/issues/Issue6229.hx

@@ -0,0 +1,27 @@
+package issues;
+
+class Vec {
+    public var x:Float;
+	public var y:Float;
+    public inline function new(x) {
+        this.x = x;
+		this.y = x;
+    }
+}
+
+class Issue6229 {
+    static inline function mkVec(x) {
+		{
+			{
+				return new Vec(x);
+			}
+		}
+	}
+
+	@:js('var a = 1 + 1;')
+	@:analyzer(no_local_dce)
+    static function test() {
+        var v = mkVec(1);
+		var a = v.x + v.y;
+    }
+}