瀏覽代碼

[cpp] bind TField subjects to temp var (closes #5113)

Simon Krajewski 9 年之前
父節點
當前提交
695d705154
共有 3 個文件被更改,包括 51 次插入5 次删除
  1. 1 0
      .gitignore
  2. 9 5
      src/optimization/analyzerTexprTransformer.ml
  3. 41 0
      tests/unit/src/unit/issues/Issue5113.hx

+ 1 - 0
.gitignore

@@ -88,3 +88,4 @@ tests/misc/projects/Issue4070/cpp/
 /tests/misc/eventLoop/eventLoop.py
 /tests/misc/eventLoop/php
 tests/display/.vscode/
+tests/unit/.vscode/

+ 9 - 5
src/optimization/analyzerTexprTransformer.ml

@@ -122,7 +122,11 @@ let rec func ctx bb tf t p =
 		| TField({eexpr = TTypeExpr _},fa) ->
 			bb,e
 		| TField(e1,fa) ->
-			let bb,e1 = value bb e1 in
+			let bb,e1 = match ctx.com.platform,e1.eexpr with
+				| Cpp,(TLocal _ | TConst _) -> value bb e1
+				| Cpp,_ -> bind_to_temp bb false e1
+				| _ -> value bb e1
+			in
 			bb,{e with eexpr = TField(e1,fa)}
 		| TArray(e1,e2) ->
 			let bb,e1,e2 = match ordered_value_list bb [e1;e2] with
@@ -271,10 +275,10 @@ let rec func ctx bb tf t p =
 						e
 				in
 				let el = Codegen.UnificationCallback.check_call check el e1.etype in
-				let bb,el = ordered_value_list bb (e1 :: el) in
-				match el with
-					| e1 :: el -> bb,{e with eexpr = TCall(e1,el)}
-					| _ -> assert false
+					let bb,el = ordered_value_list bb (e1 :: el) in
+					match el with
+						| e1 :: el -> bb,{e with eexpr = TCall(e1,el)}
+						| _ -> assert false
 		end
 	and block_element bb e = match e.eexpr with
 		(* variables *)

+ 41 - 0
tests/unit/src/unit/issues/Issue5113.hx

@@ -0,0 +1,41 @@
+package unit.issues;
+
+private class Node {
+
+    var parentNode:Node;
+
+    public function new() { }
+
+    public function getParent():Node {
+        return parentNode;
+    }
+
+    public function addChild(node:Node) {
+        node.parentNode = this;
+    }
+}
+
+
+private class Element extends Node {
+
+    public var children:Array<Node> = [];
+
+    public function new() {
+        super();
+    }
+
+    override public function getParent():Element {
+        return cast parentNode;
+    }
+}
+
+class Issue5113 extends unit.Test {
+	function test() {
+        var childEl = new Element();
+        var parentEl = new Element();
+        var parentNode = new Node();
+
+        parentEl.addChild(childEl);
+        eq(0, childEl.getParent().children.length);
+	}
+}