Browse Source

[php][php7] access to enum constructors from enum type saved to a variable (fixes #6159)

Alexander Kuzmenko 8 years ago
parent
commit
5ac9b1a8a4
3 changed files with 26 additions and 3 deletions
  1. 6 1
      src/generators/genphp.ml
  2. 6 2
      src/generators/genphp7.ml
  3. 14 0
      tests/unit/src/unit/issues/Issue6159.hx

+ 6 - 1
src/generators/genphp.ml

@@ -803,7 +803,12 @@ and gen_member_access ctx isvar e s =
 	| TAnon a ->
 		(match !(a.a_status) with
 		| EnumStatics _ ->
-			print ctx "::%s%s" (if isvar then "$" else "") (s_ident s)
+			let (isvar, access_operator) =
+				match e.eexpr with
+					| TField _ -> (false, "->")
+					| _ -> (isvar, "::")
+			in
+			print ctx "%s%s" (access_operator ^ (if isvar then "$" else "")) (s_ident s)
 		| Statics sta ->
 			let (sep, no_dollar) = if Meta.has Meta.PhpGlobal sta.cl_meta then
 					("", false)

+ 6 - 2
src/generators/genphp7.ml

@@ -2226,6 +2226,10 @@ class code_writer (ctx:Common.context) hx_type_path php_name =
 					if not written_as_probable_string then write_access "->" field_name
 				| FClosure (tcls, field) -> self#write_expr_field_closure tcls field expr
 				| FEnum (_, field) ->
+					let access_operator = match (reveal_expr expr).eexpr with
+						| TTypeExpr _ -> "::"
+						| _ -> "->"
+					in
 					if is_enum_constructor_with_args field then
 						if not self#parent_expr_is_call then
 							begin
@@ -2238,10 +2242,10 @@ class code_writer (ctx:Common.context) hx_type_path php_name =
 								self#write (", '" ^ field.ef_name ^ "')")
 							end
 						else
-							write_access "::" field.ef_name
+							write_access access_operator field.ef_name
 					else
 						begin
-							write_access "::" field.ef_name;
+							write_access access_operator field.ef_name;
 							self#write "()"
 						end
 

+ 14 - 0
tests/unit/src/unit/issues/Issue6159.hx

@@ -0,0 +1,14 @@
+package unit.issues;
+
+class Issue6159 extends unit.Test {
+    static var e = Dummy;
+
+    function test() {
+        eq(A, e.A);
+    }
+}
+
+private enum Dummy {
+	A;
+	B;
+}