瀏覽代碼

[analyzer] always consider captured vars to be used (closes #3861)

Simon Krajewski 10 年之前
父節點
當前提交
cb451a3c8c
共有 2 個文件被更改,包括 11 次插入1 次删除
  1. 1 1
      analyzer.ml
  2. 10 0
      tests/unit/src/unit/issues/Issue3861.hx

+ 1 - 1
analyzer.ml

@@ -1246,7 +1246,7 @@ end
 
 
 module LocalDce = struct
 module LocalDce = struct
 	let apply e =
 	let apply e =
-		let is_used v = Meta.has Meta.Used v.v_meta || type_has_analyzer_option v.v_type flag_no_local_dce in
+		let is_used v = Meta.has Meta.Used v.v_meta || type_has_analyzer_option v.v_type flag_no_local_dce || v.v_capture in
 		let is_ref_type t = match t with
 		let is_ref_type t = match t with
 			| TType({t_path = ["cs"],("Ref" | "Out")},_) -> true
 			| TType({t_path = ["cs"],("Ref" | "Out")},_) -> true
 			| _ -> false
 			| _ -> false

+ 10 - 0
tests/unit/src/unit/issues/Issue3861.hx

@@ -0,0 +1,10 @@
+package unit.issues;
+
+class Issue3861 extends unit.Test {
+	function test() {
+		var a;
+		var b = function() return a;
+		a = 2;
+		eq(2, b());
+	}
+}