Explorar o código

[js] look ahead for conflicting var names in blocks because that's how scoping works there (closes #3344)

Simon Krajewski %!s(int64=11) %!d(string=hai) anos
pai
achega
d8c1dac660
Modificáronse 2 ficheiros con 30 adicións e 0 borrados
  1. 16 0
      filters.ml
  2. 14 0
      tests/unit/issues/Issue3344.hx

+ 16 - 0
filters.ml

@@ -704,6 +704,22 @@ let rename_local_vars com e =
 			old()
 			old()
 		| TBlock el ->
 		| TBlock el ->
 			let old = save() in
 			let old = save() in
+			(* we have to look ahead for vars on these targets (issue #3344) *)
+			begin match com.platform with
+				| Js | Flash8 ->
+					let rec check_var e = match e.eexpr with
+						| TVar (v,eo) ->
+							(match eo with None -> () | Some e -> loop e);
+							declare v e.epos
+						| TBlock _ ->
+							()
+						| _ ->
+							Type.iter check_var e
+					in
+					List.iter check_var el
+				| _ ->
+					()
+			end;
 			List.iter loop el;
 			List.iter loop el;
 			old()
 			old()
 		| TFor (v,it,e1) ->
 		| TFor (v,it,e1) ->

+ 14 - 0
tests/unit/issues/Issue3344.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+
+class Issue3344 extends unit.Test {
+
+    static function hello() {
+		return "ok";
+    }
+
+	function test() {
+        eq("ok", Issue3344.hello());
+        var Issue3344 = 10;
+		eq(10, Issue3344);
+	}
+}