Browse Source

[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
Aleksandr Kuzmenko 5 năm trước cách đây
mục cha
commit
3c8bb291a2

+ 6 - 0
extra/CHANGES.txt

@@ -1,3 +1,9 @@
+2020-XX-XX 4.1.3
+
+	Bugfixes:
+
+	flash : fixed var shadowing issue for variables captured in a closure inside of a loop (#9624)
+
 2020-06-19 4.1.2
 2020-06-19 4.1.2
 
 
 	Bugfixes:
 	Bugfixes:

+ 5 - 1
src/context/common.ml

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