소스 검색

fix renaming variables for recursive (closes #9312)

Aleksandr Kuzmenko 5 년 전
부모
커밋
0c5f770eb8
3개의 변경된 파일15개의 추가작업 그리고 1개의 파일을 삭제
  1. 1 1
      src/filters/renameVars.ml
  2. 11 0
      tests/misc/projects/Issue9312/Main.hx
  3. 3 0
      tests/misc/projects/Issue9312/compile.hxml

+ 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
 	in
 	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;
 		Option.may (collect_vars scope) 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