浏览代码

[php7] fix `null` property access (closes #6281)

Alexander Kuzmenko 8 年之前
父节点
当前提交
d298210b81
共有 2 个文件被更改,包括 23 次插入1 次删除
  1. 10 1
      src/generators/genphp7.ml
  2. 13 0
      tests/unit/src/unit/issues/Issue6281.hx

+ 10 - 1
src/generators/genphp7.ml

@@ -764,6 +764,15 @@ let has_rtti_meta ctx mtype =
 		| None -> false
 		| None -> false
 		| Some _ -> true
 		| Some _ -> true
 
 
+(**
+	Check if specified property access requires a real class variable to be defined.
+*)
+let is_real_var_access access =
+	match access with
+		| AccNormal
+		| AccNo -> true
+		| _ -> false
+
 (**
 (**
 	Check if this var accesses and meta combination should generate a variable
 	Check if this var accesses and meta combination should generate a variable
 *)
 *)
@@ -772,7 +781,7 @@ let is_real_var field =
 		true
 		true
 	else
 	else
 		match field.cf_kind with
 		match field.cf_kind with
-			| Var { v_read = read; v_write = write } -> read = AccNormal || write = AccNormal
+			| Var { v_read = read; v_write = write } -> is_real_var_access read || is_real_var_access write
 			| _ -> false
 			| _ -> false
 
 
 (**
 (**

+ 13 - 0
tests/unit/src/unit/issues/Issue6281.hx

@@ -0,0 +1,13 @@
+package unit.issues;
+
+class Issue6281 extends unit.Test {
+    public static var check(get, null):String;
+
+    static function get_check():String {
+        return (check == null ? check = 'foo' : check);
+    }
+
+    public function test() {
+        eq('foo', check);
+    }
+}