Pārlūkot izejas kodu

bring back scoping check (closes #4751)

Simon Krajewski 9 gadi atpakaļ
vecāks
revīzija
70aedbb33e
2 mainītis faili ar 36 papildinājumiem un 1 dzēšanām
  1. 7 1
      analyzer.ml
  2. 29 0
      tests/unit/src/unit/issues/Issue4751.hx

+ 7 - 1
analyzer.ml

@@ -2009,6 +2009,12 @@ module CopyPropagation = DataFlow(struct
 		lattice := IntMap.empty
 
 	let commit ctx =
+		(* We don't care about the scope on JS and AS3 because they hoist var declarations. *)
+		let in_scope bb bb' = match ctx.com.platform with
+			| Js _ -> true
+			| Flash when Common.defined ctx.com Define.As3 -> true
+			| _ -> List.mem (List.hd bb'.bb_scopes) bb.bb_scopes
+ 		in
 		let rec commit bb e = match e.eexpr with
 			| TLocal v when not v.v_capture ->
 				begin try
@@ -2025,7 +2031,7 @@ module CopyPropagation = DataFlow(struct
 					   considering variables whose origin-variables are assigned to at most once. *)
 					let writes = (get_var_info ctx.graph v'').vi_writes in
 					begin match writes with
-						| [_] -> ()
+						| [bb'] when in_scope bb bb' -> ()
 						| _ -> leave()
 					end;
 					commit bb {e with eexpr = TLocal v'}

+ 29 - 0
tests/unit/src/unit/issues/Issue4751.hx

@@ -0,0 +1,29 @@
+package unit.issues;
+
+import unit.Test;
+
+private abstract O(Int) {
+	public inline function get():Int return this;
+}
+
+class Issue4751 extends Test{
+	static function func(v:Float) {}
+
+	function testNadako() {
+		var o:{?v:O} = {};
+		func(if (cond()) o.v.get() else throw "oh");
+	}
+
+	function testGama() {
+		var dx:Float = Math.random();
+		var dy:Float = Math.random();
+		{
+			var t = dx;
+			dx = -dy;
+			dy = t;
+		};
+		func(dy * 1.1);
+	}
+
+	static function cond() return true;
+}