Browse Source

[php] fix call()() situations (fixes #5569)

Alexander Kuzmenko 8 years ago
parent
commit
90de5f52ba
3 changed files with 30 additions and 2 deletions
  1. 11 1
      src/generators/genphp.ml
  2. 1 1
      src/generators/genphp7.ml
  3. 18 0
      tests/unit/src/unit/issues/Issue5569.hx

+ 11 - 1
src/generators/genphp.ml

@@ -76,6 +76,16 @@ let follow = Abstract.follow_with_abstracts
 *)
 *)
 let is_float expr = match follow expr.etype with TAbstract ({ a_path = ([], "Float") }, _) -> true | _ -> false
 let is_float expr = match follow expr.etype with TAbstract ({ a_path = ([], "Float") }, _) -> true | _ -> false
 
 
+(**
+	If `expr` is a TCast or TMeta, then returns underlying expression (recursively bypassing nested casts).
+	Otherwise returns `expr` as is.
+*)
+let rec reveal_expr expr =
+	match expr.eexpr with
+		| TCast (e, _) -> reveal_expr e
+		| TMeta (_, e) -> reveal_expr e
+		| _ -> expr
+
 let join_class_path path separator =
 let join_class_path path separator =
 	let result = match fst path, snd path with
 	let result = match fst path, snd path with
 	| [], s -> s
 	| [], s -> s
@@ -541,7 +551,7 @@ and gen_call ctx e el =
 			spr ctx "]";
 			spr ctx "]";
 			genargs t)
 			genargs t)
 	in
 	in
-	match e.eexpr , el with
+	match (reveal_expr e).eexpr , el with
 	| TConst TSuper , params ->
 	| TConst TSuper , params ->
 		(match ctx.curclass.cl_super with
 		(match ctx.curclass.cl_super with
 		| None -> assert false
 		| None -> assert false

+ 1 - 1
src/generators/genphp7.ml

@@ -196,7 +196,7 @@ let add_php_prefix ctx type_path =
 		| (pack, name) -> ((get_php_prefix ctx) @ pack, name)
 		| (pack, name) -> ((get_php_prefix ctx) @ pack, name)
 
 
 (**
 (**
-	If `expr` is a TCast returns underlying expression (recursively bypassing nested casts).
+	If `expr` is a TCast or TMeta, then returns underlying expression (recursively bypassing nested casts).
 	Otherwise returns `expr` as is.
 	Otherwise returns `expr` as is.
 *)
 *)
 let rec reveal_expr expr =
 let rec reveal_expr expr =

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

@@ -0,0 +1,18 @@
+package unit.issues;
+
+import haxe.Constraints;
+
+class Issue5569 extends unit.Test {
+	function test() {
+		var namesToFunctions:Map<String, Function> = new Map<String, Function>();
+		var noArgs:String = "noArgs";
+		var withArgs:String = "withArgs";
+		namesToFunctions.set(noArgs, function() {});
+		namesToFunctions.set(withArgs, function(a:Int) {});
+
+		namesToFunctions.get(noArgs)();
+		namesToFunctions.get(withArgs)(1);
+
+		t(true);
+	}
+}