Sfoglia il codice sorgente

drop var/assign/return expression when TContinue/TBreak is used as its value (closes #3197)

Dan Korostelev 11 anni fa
parent
commit
36b4aa5f7f
2 ha cambiato i file con 21 aggiunte e 0 eliminazioni
  1. 2 0
      filters.ml
  2. 19 0
      tests/unit/issues/Issue3197.hx

+ 2 - 0
filters.ml

@@ -200,6 +200,8 @@ let promote_complex_rhs ctx e =
 			{ e with eexpr = TMeta(m,loop f e1)}
 		| TReturn _ | TThrow _ ->
 			find e
+		| TContinue | TBreak ->
+			e
 		| TCast(e1,None) when ctx.config.pf_ignore_unsafe_cast ->
 			loop f e1
 		| _ ->

+ 19 - 0
tests/unit/issues/Issue3197.hx

@@ -0,0 +1,19 @@
+package unit.issues;
+
+class Issue3197 extends Test {
+	function test() {
+        var v = "good";
+        for (i in 0...10) {
+            v = if (i == 1) "bad" else break;
+        }
+        eq(v, "good");
+
+        var a = [];
+        for (i in 0...10) {
+            var v = if (i == 1) i else continue;
+            a.push(v);
+        }
+        eq(a.length, 1);
+        eq(a[0], 1);
+	}
+}