Browse Source

fix renaming variables for recursive (closes #9312)

Aleksandr Kuzmenko 5 years ago
parent
commit
0c5f770eb8

+ 1 - 1
src/filters/renameVars.ml

@@ -198,7 +198,7 @@ let rec collect_vars ?(in_block=false) rc scope e =
 		| _ -> collect_vars ~in_block:false rc
 		| _ -> collect_vars ~in_block:false rc
 	in
 	in
 	match e.eexpr with
 	match e.eexpr with
-	| TVar (v, e_opt) when rc.rc_hoisting ->
+	| TVar (v, e_opt) when rc.rc_hoisting || (match e_opt with Some { eexpr = TFunction _ } -> true | _ -> false) ->
 		declare_var rc scope v;
 		declare_var rc scope v;
 		Option.may (collect_vars scope) e_opt
 		Option.may (collect_vars scope) e_opt
 	| TVar (v, e_opt) ->
 	| TVar (v, e_opt) ->

+ 11 - 0
tests/misc/projects/Issue9312/Main.hx

@@ -0,0 +1,11 @@
+class Main {
+	static function main() {
+		var fn:(Array<Int>)->Void;
+		fn = function(a:Array<Int>):Void {
+			for(i in a) {
+				fn([i]);
+			}
+		}
+		fn([1,2,3]);
+	}
+}

+ 3 - 0
tests/misc/projects/Issue9312/compile.hxml

@@ -0,0 +1,3 @@
+-main Main
+-js bin/test.js
+-D js-es=6