Sfoglia il codice sorgente

[analyzer] don't process block elements in dead code

closes #10261
Simon Krajewski 4 anni fa
parent
commit
785a70ef35

+ 2 - 2
src/optimization/analyzerTexprTransformer.ml

@@ -293,8 +293,8 @@ let rec func ctx bb tf t p =
 	and block_element_plus bb (e,efinal) f =
 		let bb = block_element bb e in
 		let bb = match efinal with
-			| None -> bb
-			| Some e -> block_element bb (f e)
+			| Some e when bb != g.g_unreachable -> block_element bb (f e)
+			| _ -> bb
 		in
 		bb
 	and block_element_value bb e f =

+ 20 - 0
tests/unit/src/unit/issues/Issue10261.hx

@@ -0,0 +1,20 @@
+package unit.issues;
+
+import utest.Assert;
+
+class Issue10261 extends Test {
+	function call(x:Int) {
+		return "";
+	}
+
+	function write() {
+		return {
+			while (true) {}
+			call(0);
+		}
+	}
+
+	function test() {
+		Assert.pass();
+	}
+}