Skip to content

Commit

Permalink
[analyzer] do not create temp vars for non-TInst TFuns (closes #5082)
Browse files Browse the repository at this point in the history
  • Loading branch information
Simn committed Jul 18, 2016
1 parent a116da7 commit 910f782
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/optimization/analyzerTexprTransformer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,15 @@ let rec func ctx bb tf t p =
) (bb,[]) el in
bb,List.rev values
and bind_to_temp bb sequential e =
let is_probably_not_affected e e1 fa = match extract_field fa with
| Some {cf_kind = Method MethNormal} -> true
| _ -> match follow e.etype,follow e1.etype with
| TFun _,TInst _ -> false
| TFun _,_ -> true (* We don't know what's going on here, don't create a temp var (see #5082). *)
| _ -> false
in
let rec loop fl e = match e.eexpr with
| TField(e1,fa) when (match extract_field fa with Some {cf_kind = Method MethNormal} -> true | _ -> false) ->
| TField(e1,fa) when is_probably_not_affected e e1 fa ->
loop ((fun e' -> {e with eexpr = TField(e',fa)}) :: fl) e1
| _ ->
fl,e
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/src/unit/issues/Issue5082.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package unit.issues;

private enum E {
Tiles(x:Dynamic);
TileInstances(x:Dynamic);
}

@:keep
private class Content {
public var find:String -> Content;
public function new() {
find = function(s:String) return this;
}

public function spectrum(s:String, d:Dynamic) {
return this;
}

public function closest(s:String) {
return this;
}

public function css(s:String) {
return "foo";
}
}

class Issue5082 extends unit.Test {
function test() {
var l = {data: Tiles([]), props:{color:""}, idToIndex: null};
var content = new Content();
var x = (untyped content.find("[name=color]")).spectrum("set", toColor(l.props.color)).closest(".item").css( { display : l.idToIndex == null && !l.data.match(Tiles(_) | TileInstances(_)) ? "" : "none" } );
eq("foo", x);
}

static function toColor(d:Dynamic) return d;
}

0 comments on commit 910f782

Please sign in to comment.