From 910f782abbe24a910c2ca977562e982468ceb034 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Mon, 18 Jul 2016 09:23:18 +0200 Subject: [PATCH] [analyzer] do not create temp vars for non-TInst TFuns (closes #5082) --- src/optimization/analyzerTexprTransformer.ml | 9 ++++- tests/unit/src/unit/issues/Issue5082.hx | 37 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 tests/unit/src/unit/issues/Issue5082.hx diff --git a/src/optimization/analyzerTexprTransformer.ml b/src/optimization/analyzerTexprTransformer.ml index 8933175183b..7f85eccd71e 100644 --- a/src/optimization/analyzerTexprTransformer.ml +++ b/src/optimization/analyzerTexprTransformer.ml @@ -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 diff --git a/tests/unit/src/unit/issues/Issue5082.hx b/tests/unit/src/unit/issues/Issue5082.hx new file mode 100644 index 00000000000..02deeb9442f --- /dev/null +++ b/tests/unit/src/unit/issues/Issue5082.hx @@ -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; +} \ No newline at end of file