瀏覽代碼

[php7] fix setting values in a map stored in another map (fixes #6257)

Alexander Kuzmenko 8 年之前
父節點
當前提交
7e0e7580dd
共有 3 個文件被更改,包括 16 次插入3 次删除
  1. 1 0
      extra/CHANGES.txt
  2. 4 3
      src/generators/genphp7.ml
  3. 11 0
      tests/unit/src/unit/issues/Issue6257.hx

+ 1 - 0
extra/CHANGES.txt

@@ -6,6 +6,7 @@ xxxx-xx-xx: 3.4.3
 	php7: fix using enum constructor with arguments as a call argument (#6177)
 	php7: fix accessing methods on dynamic values (#6211)
 	php7: fix `null` property access (#6281)
+	php7: fix setting values in a map stored in another map (#6257)
 	php/php7: fixed accessing enum constructors on enum type stored to a variable (#6159)
 	php/php7: fix "cannot implement previously implemented interface" (#6208)
 	php: fix invoking functions stored in dynamic static vars (#6158)

+ 4 - 3
src/generators/genphp7.ml

@@ -382,13 +382,14 @@ let need_parenthesis_for_binop current parent =
 *)
 let needs_dereferencing for_assignment expr =
 	let rec is_create target_expr =
-		match target_expr.eexpr with
+		match (reveal_expr target_expr).eexpr with
 			| TParenthesis e -> is_create e
 			| TCast (e, _) -> is_create e
 			| TNew _ -> for_assignment
 			| TArrayDecl _ -> for_assignment
 			| TObjectDecl _ -> for_assignment
 			| TConst TNull -> true
+			| TIf _ -> true
 			(* some of `php.Syntax` methods *)
 			| TCall ({ eexpr = TField (_, FStatic ({ cl_path = syntax_type_path }, { cf_name = name })) }, _) ->
 				(match name with
@@ -397,7 +398,7 @@ let needs_dereferencing for_assignment expr =
 				)
 			| _ -> false
 	in
-	match expr.eexpr with
+	match (reveal_expr expr).eexpr with
 		| TField (target_expr, _) -> is_create target_expr
 		| TArray (target_expr, _) -> is_create target_expr
 		| _ -> false
@@ -1574,7 +1575,7 @@ class code_writer (ctx:Common.context) hx_type_path php_name =
 				| TBinop (operation, expr1, expr2) -> self#write_expr_binop operation expr1 expr2
 				| TField (fexpr, access) when is_php_global expr -> self#write_expr_php_global expr
 				| TField (fexpr, access) when is_php_class_const expr -> self#write_expr_php_class_const expr
-				| TField (fexpr, access) when needs_dereferencing false expr -> self#write_expr (self#dereference expr)
+				| TField (fexpr, access) when needs_dereferencing (self#is_in_write_context) expr -> self#write_expr (self#dereference expr)
 				| TField (fexpr, access) -> self#write_expr_field fexpr access
 				| TTypeExpr mtype -> self#write_expr_type mtype
 				| TParenthesis expr ->

+ 11 - 0
tests/unit/src/unit/issues/Issue6257.hx

@@ -0,0 +1,11 @@
+package unit.issues;
+
+class Issue6257 extends unit.Test {
+	function test() {
+		var packages:Map<String, Map<String, String>> = ["" => new Map()];
+		packages.get("").set("foo", "bar");
+		var obj = {prop:"foo"};
+		(obj.prop == "foo" ? obj : null).prop = "bar";
+		eq("bar", packages.get("").get("foo"));
+	}
+}