Browse Source

[php7] dreference field access on `null`; more cases for #4988

Alexander Kuzmenko 8 năm trước cách đây
mục cha
commit
4ee6659865
2 tập tin đã thay đổi với 4 bổ sung1 xóa
  1. 2 1
      src/generators/genphp7.ml
  2. 2 0
      tests/unit/src/unit/issues/Issue4988.hx

+ 2 - 1
src/generators/genphp7.ml

@@ -1574,7 +1574,8 @@ 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 (expr, access) -> self#write_expr_field expr access
+				| TField (fexpr, access) when needs_dereferencing false 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 ->
 					self#write "(";

+ 2 - 0
tests/unit/src/unit/issues/Issue4988.hx

@@ -9,6 +9,8 @@ class Issue4988 extends Test {
 			try {
 				var d:{i:Null<Int>} = null;
 				value = (d.i > 0);
+				(null:Dynamic).nonExistent();
+				null.nonExistent();
 				t(false);
 			} catch(e:Dynamic) {
 				t(true);