فهرست منبع

[php7] fix FClosure field access on dynamic methods

Alexander Kuzmenko 8 سال پیش
والد
کامیت
63a404f543
1فایلهای تغییر یافته به همراه26 افزوده شده و 17 حذف شده
  1. 26 17
      src/generators/genphp7.ml

+ 26 - 17
src/generators/genphp7.ml

@@ -1719,7 +1719,7 @@ class virtual type_builder ctx wrapper =
 			Writes TBlock to output buffer
 			Writes TBlock to output buffer
 		*)
 		*)
 		method private write_expr_block block_expr =
 		method private write_expr_block block_expr =
-			(* Check if parent expr could not contain blocks in PHP, adn this block needs to be wrapped in a closure. *)
+			(* Check if parent expr could not contain blocks in PHP, and this block needs to be wrapped in a closure. *)
 			let needs_closure = match self#parent_expr with
 			let needs_closure = match self#parent_expr with
 				| None -> false
 				| None -> false
 				| Some e ->
 				| Some e ->
@@ -2240,22 +2240,31 @@ class virtual type_builder ctx wrapper =
 			Writes FClosure field access to output buffer
 			Writes FClosure field access to output buffer
 		*)
 		*)
 		method private write_expr_field_closure tcls field expr =
 		method private write_expr_field_closure tcls field expr =
-			let new_closure = "new " ^ (self#use hxclosure_type_path) in
-			match expr.eexpr with
-				| TTypeExpr mtype ->
-					let class_name = self#use_t (type_of_module_type mtype) in
-					self#write (new_closure ^ "(" ^ class_name ^ "::class, '" ^ (field_name field) ^ "')");
-				| _ ->
-					self#write (new_closure ^ "(");
-					(match follow expr.etype with
-						| TInst ({ cl_path = ([], "String") }, []) ->
-							self#write ((self#use hxdynamicstr_type_path) ^ "::wrap(");
-							self#write_expr expr;
-							self#write ")"
-						| _ ->
-							self#write_expr expr
-					);
-					self#write (", '" ^ (field_name field) ^ "')")
+			if is_dynamic_method field then
+				match expr.eexpr with
+					| TTypeExpr mtype ->
+						let class_name = self#use_t (type_of_module_type mtype) in
+						self#write (class_name ^ "::$" ^ (field_name field) ^ "'");
+					| _ ->
+						self#write_expr expr;
+						self#write ("->" ^ (field_name field))
+			else
+				let new_closure = "new " ^ (self#use hxclosure_type_path) in
+				match expr.eexpr with
+					| TTypeExpr mtype ->
+						let class_name = self#use_t (type_of_module_type mtype) in
+						self#write (new_closure ^ "(" ^ class_name ^ "::class, '" ^ (field_name field) ^ "')");
+					| _ ->
+						self#write (new_closure ^ "(");
+						(match follow expr.etype with
+							| TInst ({ cl_path = ([], "String") }, []) ->
+								self#write ((self#use hxdynamicstr_type_path) ^ "::wrap(");
+								self#write_expr expr;
+								self#write ")"
+							| _ ->
+								self#write_expr expr
+						);
+						self#write (", '" ^ (field_name field) ^ "')")
 		(**
 		(**
 			Write anonymous object declaration to output buffer
 			Write anonymous object declaration to output buffer
 		*)
 		*)