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

[flash] use hoisted/function var scoping for Flash (closes #9624)

because even though it's a bytecode target, it does look captured vars by name, at least that's how Haxe generates it
Dan Korostelev 5 жил өмнө
parent
commit
308ed91e0b

+ 5 - 1
src/context/common.ml

@@ -472,7 +472,11 @@ let get_config com =
 					["flash";"errors"],"Error";
 					["haxe"],"Exception";
 				];
-			}
+			};
+			pf_scoping = {
+				vs_scope = FunctionScope;
+				vs_flags = [VarHoisting];
+			};
 		}
 	| Php ->
 		{

+ 28 - 0
tests/unit/src/unit/issues/Issue9624.hx

@@ -0,0 +1,28 @@
+package unit.issues;
+
+class Issue9624 extends unit.Test {
+	function test() {
+		var result = 0;
+		var index = 0;
+
+		function f() {
+			while (index < 5) {
+				index = index + 1;
+				var index = index;
+				function capture() {
+					result += index;
+				}
+				// prevent inlining everything
+				capture();
+				capture();
+			}
+		}
+
+		f();
+		// prevent inlining everything
+		index = 0;
+		f();
+
+		eq(60, result);
+	}
+}