Browse Source

[php7] dereference Syntax.binop(), Syntax.array() and Syntax.object() in left part of assignments (fixes #5923)

Alexander Kuzmenko 8 years ago
parent
commit
e2e35506bc
3 changed files with 26 additions and 0 deletions
  1. 2 0
      extra/CHANGES.txt
  2. 6 0
      src/generators/genphp7.ml
  3. 18 0
      tests/unit/src/unit/issues/Issue5923.hx

+ 2 - 0
extra/CHANGES.txt

@@ -3,6 +3,8 @@
 	Bugfixes:
 
 	all : fixed issue with side-effect detection when optimizing (#5911)
+	php7 : Allow user-defined modules in `php` package (#5921)
+	php7 : Dereference some of `php.Syntax` methods if required (#5923)
 
 2016-12-24: 3.4.0-RC2
 

+ 6 - 0
src/generators/genphp7.ml

@@ -364,6 +364,12 @@ let needs_dereferencing expr =
 			| TArrayDecl _ -> true
 			| TObjectDecl _ -> true
 			| TConst TNull -> true
+			(* some of `php.Syntax` methods *)
+			| TCall ({ eexpr = TField (_, FStatic ({ cl_path = syntax_type_path }, { cf_name = name })) }, _) ->
+				(match name with
+					| "binop" | "object" | "array" -> true
+					| _ -> false
+				)
 			| _ -> false
 	in
 	match expr.eexpr with

+ 18 - 0
tests/unit/src/unit/issues/Issue5923.hx

@@ -0,0 +1,18 @@
+package unit.issues;
+
+#if php7
+import php.Syntax.*;
+#end
+
+class Issue5923 extends unit.Test {
+#if php7
+	function test() {
+		//These expressions should not fail at runtime
+		binop({}, '??', null).value = 1;
+		object(arrayDecl()).value = 1;
+		array({})['value'] = 1;
+
+		t(true);
+	}
+#end
+}