Browse Source

[analyzer] fix unbound var call side-effect handling

closes #5745
Simon Krajewski 9 years ago
parent
commit
4412475fc8
2 changed files with 29 additions and 3 deletions
  1. 4 3
      src/optimization/analyzerTexpr.ml
  2. 25 0
      tests/optimization/src/issues/Issue5745.hx

+ 4 - 3
src/optimization/analyzerTexpr.ml

@@ -711,8 +711,6 @@ module Fusion = struct
 							in
 							if not !found then raise Exit;
 							{e with eexpr = TSwitch(e1,cases,edef)}
-						| TCall({eexpr = TLocal v},_) when is_really_unbound v ->
-							e
 						(* locals *)
 						| TLocal v2 when v1 == v2 && not !blocked ->
 							found := true;
@@ -769,7 +767,10 @@ module Fusion = struct
 							if not !found && (has_state_write ir || has_any_field_write ir) then raise Exit;
 							{e with eexpr = TCall(ef,el)}
 						| TCall(e1,el) ->
-							let e1,el = handle_call e1 el in
+							let e1,el = match e1.eexpr with
+								| TLocal v when is_really_unbound v -> e1,el
+								| _ -> handle_call e1 el
+							in
 							if not !found && (((has_state_read ir || has_any_field_read ir)) || has_state_write ir || has_any_field_write ir) then raise Exit;
 							{e with eexpr = TCall(e1,el)}
 						| TObjectDecl fl ->

+ 25 - 0
tests/optimization/src/issues/Issue5745.hx

@@ -0,0 +1,25 @@
+package issues;
+
+class Issue5745 {
+	@:js('
+		var fn = "filename";
+		var v = cat(fn);
+		runProgram.apply(undefined, ["rm",fn]);
+		console.log(v);
+	')
+    static function test() {
+        var fn = 'filename';
+        var v = Shell.cat(fn);
+        Shell.runProgram(['rm', fn]);
+        trace(v);
+    }
+}
+
+class Shell {
+    public inline static function runProgram(args:Array<String>):Int {
+        return untyped __js__('runProgram.apply(undefined, {0})', args);
+    }
+    public inline static function cat(v:String):String {
+        return untyped __js__('cat({0})', v);
+    }
+}