Răsfoiți Sursa

rewrite unify_call_args

Simon Krajewski 11 ani în urmă
părinte
comite
6c54b6b5ad
3 a modificat fișierele cu 173 adăugiri și 182 ștergeri
  1. 10 9
      codegen.ml
  2. 15 1
      typecore.ml
  3. 148 172
      typer.ml

+ 10 - 9
codegen.ml

@@ -1503,15 +1503,15 @@ struct
 
 	let rec rm_duplicates acc ret = match ret with
 		| [] -> acc
-		| ( el, t ) :: ret when List.exists (fun (_,t2) -> type_iseq t t2) acc ->
+		| ( el, t, _ ) :: ret when List.exists (fun (_,t2,_) -> type_iseq t t2) acc ->
 			rm_duplicates acc ret
 		| r :: ret ->
 			rm_duplicates (r :: acc) ret
 
-	let s_options rated =
+(* 	let s_options rated =
 		String.concat ",\n" (List.map (fun ((_,t),rate) ->
 			"( " ^ (String.concat "," (List.map (fun (i,i2) -> string_of_int i ^ ":" ^ string_of_int i2) rate)) ^ " ) => " ^ (s_type (print_context()) t)
-		) rated)
+		) rated) *)
 
 	let count_optionals elist =
 		List.fold_left (fun acc (_,is_optional) -> if is_optional then acc + 1 else acc) 0 elist
@@ -1519,7 +1519,7 @@ struct
 	let rec fewer_optionals acc compatible = match acc, compatible with
 		| _, [] -> acc
 		| [], c :: comp -> fewer_optionals [c] comp
-		| (elist_acc, _) :: _, ((elist, _) as cur) :: comp ->
+		| (elist_acc, _, _) :: _, ((elist, _, _) as cur) :: comp ->
 			let acc_opt = count_optionals elist_acc in
 			let comp_opt = count_optionals elist in
 			if acc_opt = comp_opt then
@@ -1530,7 +1530,8 @@ struct
 				fewer_optionals [cur] comp
 
 	let reduce_compatible compatible = match fewer_optionals [] (rm_duplicates [] compatible) with
-		| [] -> [] | [v] -> [v]
+		| [] -> []
+		| [v] -> [v]
 		| compatible ->
 			(* convert compatible into ( rate * compatible_type ) list *)
 			let rec mk_rate acc elist args = match elist, args with
@@ -1543,8 +1544,8 @@ struct
 
 			let rated = ref [] in
 			List.iter (function
-				| (elist,TFun(args,ret)) -> (try
-					rated := ( (elist,TFun(args,ret)), mk_rate [] elist args ) :: !rated
+				| (elist,TFun(args,ret),d) -> (try
+					rated := ( (elist,TFun(args,ret),d), mk_rate [] elist args ) :: !rated
 					with | Not_found -> ())
 				| _ -> assert false
 			) compatible;
@@ -1561,10 +1562,10 @@ struct
 						loop ( (rover,rargs) :: best ) rem
 			in
 
-			List.map fst (loop [] !rated)
+			let r = loop [] !rated in
+			List.map fst r
 end;;
 
-
 module UnificationCallback = struct
 	let tf_stack = ref []
 

+ 15 - 1
typecore.ml

@@ -122,13 +122,20 @@ and typer = {
 	mutable on_error : typer -> string -> pos -> unit;
 }
 
-type error_msg =
+type call_error =
+	| Not_enough_arguments
+	| Too_many_arguments
+	| Could_not_unify of error_msg
+	| Cannot_skip_non_nullable of string
+
+and error_msg =
 	| Module_not_found of path
 	| Type_not_found of path * string
 	| Unify of unify_error list
 	| Custom of string
 	| Unknown_ident of string
 	| Stack of error_msg * error_msg
+	| Call_error of call_error
 
 exception Fatal_error of string * Ast.pos
 
@@ -253,6 +260,13 @@ let rec error_msg = function
 	| Unknown_ident s -> "Unknown identifier : " ^ s
 	| Custom s -> s
 	| Stack (m1,m2) -> error_msg m1 ^ "\n" ^ error_msg m2
+	| Call_error err -> s_call_error err
+
+and s_call_error = function
+	| Not_enough_arguments -> "Not enough arguments"
+	| Too_many_arguments -> "Too many arguments"
+	| Could_not_unify err -> error_msg err
+	| Cannot_skip_non_nullable s -> "Cannot skip non-nullable argument " ^ s
 
 let pass_name = function
 	| PBuildModule -> "build-module"

+ 148 - 172
typer.ml

@@ -641,155 +641,131 @@ let is_forced_inline c cf =
 	| _ when Meta.has Meta.Extern cf.cf_meta -> true
 	| _ -> false
 
-let rec unify_call_args ctx ?(overloads=None) cf el args r p inline =
-	(* 'overloads' will carry a ( return_result ) list, called 'compatible' *)
-	(* it's used to correctly support an overload selection algorithm *)
-	let overloads, compatible, legacy = match cf, overloads with
-		| Some(TInst(c,pl),f), None when ctx.com.config.pf_overload && Meta.has Meta.Overload f.cf_meta ->
-				let overloads = List.filter (fun (_,f2) ->
-					not (f == f2) && (f2.cf_public || can_access ctx ~in_overload:true c f2 false)
-				) (Typeload.get_overloads c f.cf_name) in
-				if overloads = [] then (* is static function *)
-					let overloads = List.map (fun f -> f.cf_type, f) f.cf_overloads in
-					let is_static = f.cf_name <> "new" in
-					List.filter (fun (_,f) -> can_access ctx ~in_overload:true c f is_static) overloads, [], false
-				else
-					overloads, [], false
-		| Some(_,f), None ->
-				List.map (fun f -> f.cf_type, f) f.cf_overloads, [], true
-		| _, Some s ->
-				s
-		| _ -> [], [], true
-	in
-	let next ?retval () =
-		let compatible = Option.map_default (fun r -> r :: compatible) compatible retval in
-		match cf, overloads with
-		| Some (TInst(c,pl),_), (ft,o) :: l ->
-			let o = { o with cf_type = ft } in
-			let args, ret = (match follow (apply_params c.cl_params pl (field_type ctx c pl o p)) with (* I'm getting non-followed types here. Should it happen? *)
-				| TFun (tl,t) -> tl, t
-				| _ -> assert false
-			) in
-			Some (unify_call_args ctx ~overloads:(Some (l,compatible,legacy)) (Some (TInst(c,pl),o)) el args ret p inline)
-		| Some (t,_), (ft,o) :: l ->
-			let o = { o with cf_type = ft } in
-			let args, ret = (match Type.field_type o with
-				| TFun (tl,t) -> tl, t
-				| _ -> assert false
-			) in
-			Some (unify_call_args ctx ~overloads:(Some (l,compatible,legacy)) (Some (t, o)) el args ret p inline)
-		| _ ->
-			match compatible with
-			| [] -> None
-			| [acc,t] -> Some (List.map fst acc, t)
-			| comp ->
-				match Codegen.Overloads.reduce_compatible compatible with
-				| [acc,t] -> Some (List.map fst acc, t)
-				| (acc,t) :: _ -> (* ambiguous overload *)
-					let name = match cf with | Some(_,f) -> "'" ^ f.cf_name ^ "' " | _ -> "" in
-					let format_amb = String.concat "\n" (List.map (fun (_,t) ->
-						"Function " ^ name ^ "with type " ^ (s_type (print_context()) t)
-					) compatible) in
-					display_error ctx ("This call is ambiguous between the following methods:\n" ^ format_amb) p;
-					Some (List.map fst acc,t)
-				| [] -> None
-	in
-	let fun_details() =
-		let format_arg = (fun (name,opt,_) -> (if opt then "?" else "") ^ name) in
-		"Function " ^ (match cf with None -> "" | Some (_,f) -> "'" ^ f.cf_name ^ "' ") ^ "requires " ^ (if args = [] then "no arguments" else "arguments : " ^ String.concat ", " (List.map format_arg args))
-	in
-	let invalid_skips = ref [] in
-	let error acc txt =
-		match next() with
-		| Some l -> l
-		| None ->
-		display_error ctx (txt ^ " arguments\n" ^ (fun_details())) p;
-		List.rev (List.map fst acc), (TFun(args,r))
+let rec unify_call_args' ctx el args r p inline force_inline =
+	let call_error err p =
+		raise (Error (Call_error err,p))
 	in
 	let arg_error ul name opt p =
-		match next() with
-		| Some l -> l
-		| None -> raise (Error (Stack (Unify ul,Custom ("For " ^ (if opt then "optional " else "") ^ "function argument '" ^ name ^ "'")), p))
-	in
-	let rec no_opt = function
-		| [] -> []
-		| ({ eexpr = TConst TNull },true) :: l -> no_opt l
-		| l -> l
+		let err = Stack (Unify ul,Custom ("For " ^ (if opt then "optional " else "") ^ "function argument '" ^ name ^ "'")) in
+		call_error (Could_not_unify err) p
 	in
-	let rec default_value t po =
+	let rec default_value name t =
 		if is_pos_infos t then
 			let infos = mk_infos ctx p [] in
 			let e = type_expr ctx infos (WithType t) in
-			(e, true)
-		else begin
-			if not ctx.com.config.pf_can_skip_non_nullable_argument then begin match po with
-				| Some (name,p) when not (is_nullable t) -> invalid_skips := (name,p) :: !invalid_skips;
-				| _ -> ()
-			end;
-			(null (ctx.t.tnull t) p, true)
-		end
+			e
+		else
+			null (ctx.t.tnull t) p
 	in
-	let force_inline, is_extern = match cf with Some(TInst(c,_),f) -> is_forced_inline (Some c) f, c.cl_extern | _ -> false, false in
-	let rec loop acc l l2 skip check_rest =
-		match l , l2 with
-		| [] , [] ->
-			begin match !invalid_skips with
-				| [] -> ()
-				| skips -> List.iter (fun (name,p) -> display_error ctx ("Cannot skip non-nullable argument " ^ name) p) skips
-			end;
-			let args,tf = if not (inline && (ctx.g.doinline || force_inline)) && not ctx.com.config.pf_pad_nulls then
-				List.rev (no_opt acc), (TFun(args,r))
-			else
-				List.rev (acc), (TFun(args,r))
-			in
-			if not legacy && ctx.com.config.pf_overload then
-				match next ~retval:(args,tf) () with
-				| Some l -> l
-				| None ->
-					display_error ctx ("No overloaded function matches the arguments. Are the arguments correctly typed?") p;
-					List.map fst args, tf
-			else
-				List.map fst args, tf
-		| l , [(name,opt,t)] when check_rest ->
-			(match follow t with
+	let skipped = ref [] in
+	let skip name ul t =
+		if not ctx.com.config.pf_can_skip_non_nullable_argument && not (is_nullable t) then
+			call_error (Cannot_skip_non_nullable name) p;
+		skipped := (name,ul) :: !skipped;
+		default_value name t
+	in
+	(* let force_inline, is_extern = match cf with Some(TInst(c,_),f) -> is_forced_inline (Some c) f, c.cl_extern | _ -> false, false in *)
+	let force_inline, is_extern = false, false in
+	let type_against t e =
+		let e = type_expr ctx e (WithTypeResume t) in
+		(try unify_raise ctx e.etype t e.epos with Error (Unify l,p) -> raise (WithTypeError (l,p)));
+		let e = Codegen.AbstractCast.check_cast ctx t e p in
+		e
+	in
+	let rec loop el args = match el,args with
+		| [],[] ->
+			[]
+		| _,[name,false,t] when (match follow t with TAbstract({a_path = ["haxe"],"Rest"},_) -> true | _ -> false) ->
+			begin match follow t with
 				| TAbstract({a_path=(["haxe"],"Rest")},[t]) ->
-					let rec process acc el =
-						match el with
-						| [] -> acc
-						| ee :: rest ->
-							let e = type_expr ctx ee (WithTypeResume t) in
-							begin try
-								unify_raise ctx e.etype t e.epos
-							with Error (Unify ul,p) ->
-								raise (Error (Stack (Unify ul,Custom ("For rest function argument '" ^ name ^ "'")), p))
-							end;
-							process ((Codegen.AbstractCast.check_cast ctx t e p,false) :: acc) rest
-					in
-					loop (process acc l) [] [] skip false
+					(try List.map (fun e -> type_against t e,false) el with WithTypeError(ul,p) -> arg_error ul name false p)
 				| _ ->
-					loop acc l l2 skip false)
-		| [] , (_,false,_) :: _ ->
-			error (List.fold_left (fun acc (_,_,t) -> default_value t None :: acc) acc l2) "Not enough"
-		| [] , (name,true,t) :: l ->
-			loop (default_value t None :: acc) [] l skip check_rest
-		| _ , [] ->
-			(match List.rev skip with
-			| [] -> error acc "Too many"
-			| [name,ul] -> arg_error ul name true p
-			| (name,ul) :: _ -> arg_error (Unify_custom ("Invalid arguments\n" ^ fun_details()) :: ul) name true p)
-		| ee :: l, (name,opt,t) :: l2 ->
-			try
-				let e = type_expr ctx ee (WithTypeResume t) in
-				(try unify_raise ctx e.etype t e.epos with Error (Unify l,p) -> raise (WithTypeError (l,p)));
-				loop ((Codegen.AbstractCast.check_cast ctx t e p,false) :: acc) l l2 skip check_rest
+					assert false
+			end
+		| [],(_,false,_) :: _ ->
+			call_error Not_enough_arguments p
+		| [],(name,true,t) :: args ->
+			begin match loop [] args with
+				| [] when not (inline && (ctx.g.doinline || force_inline)) && not ctx.com.config.pf_pad_nulls -> []
+				| args ->
+					let e_def = default_value name t in
+					(e_def,true) :: args
+			end
+		| (_,p) :: _, [] ->
+			begin match List.rev !skipped with
+				| [] -> call_error Too_many_arguments p
+				| (s,ul) :: _ -> arg_error ul s true p
+			end
+		| e :: el,(name,opt,t) :: args ->
+			begin try
+				let e = type_against t e in
+				(e,opt) :: loop el args
 			with
 				WithTypeError (ul,p) ->
 					if opt then
-						loop (default_value t (Some (name,p)) :: acc) (ee :: l) l2 ((name,ul) :: skip) check_rest
+						let e_def = skip name ul t in
+						(e_def,true) :: loop (e :: el) args
 					else
 						arg_error ul name false p
+			end
+	in
+	let el = loop el args in
+	el,TFun(args,r)
+
+let unify_call_args ctx el args r p inline force_inline =
+	let el,tf = unify_call_args' ctx el args r p inline force_inline in
+	List.map fst el,tf
+
+let unify_field_call ctx fa el args ret p inline =
+	let map_cf cf = monomorphs cf.cf_params cf.cf_type,cf in
+	let expand_overloads cf =
+		(TFun(args,ret),cf) :: (List.map map_cf cf.cf_overloads)
+	in
+	let is_overload,candidates,map,mk_fa = match fa with
+		| FStatic(c,cf) ->
+			Meta.has Meta.Overload cf.cf_meta,expand_overloads cf,(fun t -> t),(fun cf -> FStatic(c,cf))
+		| FAnon cf ->
+			Meta.has Meta.Overload cf.cf_meta,expand_overloads cf,(fun t -> t),(fun cf -> FAnon cf)
+		| FInstance(c,tl,cf) ->
+			let cfl = if cf.cf_name = "new" || not (Meta.has Meta.Overload cf.cf_meta && ctx.com.config.pf_overload) then
+				List.map map_cf cf.cf_overloads
+			else
+				List.map (fun (t,cf) -> (monomorphs cf.cf_params t), cf) (Typeload.get_overloads c cf.cf_name)
+			in
+			Meta.has Meta.Overload cf.cf_meta,(TFun(args,ret),cf) :: cfl,(apply_params c.cl_params tl),(fun cf -> FInstance(c,tl,cf))
+		| _ ->
+			error "Invalid field call" p
+	in
+	let is_forced_inline = false in
+	let candidates,failures = List.fold_left (fun (candidates,failures) (t,cf) ->
+		begin try
+			begin match follow (map t) with
+				| TFun(args,ret) ->
+					let el,tf = unify_call_args' ctx el args ret p inline is_forced_inline in
+					let mk_call ethis =
+						let ef = mk (TField(ethis,fa)) tf p in
+						make_call ctx ef (List.map fst el) ret p
+					in
+					(el,tf,mk_call) :: candidates,failures
+				| _ ->
+					assert false
+			end
+		with Error (Call_error _,_) as err ->
+			candidates,err :: failures
+		end
+	) ([],[]) candidates in
+	let candidates = if is_overload && ctx.com.config.pf_overload then
+		Codegen.Overloads.reduce_compatible candidates
+	else
+		List.rev candidates
 	in
-	loop [] el args [] is_extern
+	match candidates with
+		| [] ->
+			begin match List.rev failures with
+				| err :: _ -> raise err
+				| _ -> assert false
+			end
+		| (el,tf,mk_call) :: _ -> List.map fst el,tf,mk_call
 
 let fast_enum_field e ef p =
 	let et = mk (TTypeExpr (TEnumDecl e)) (TAnon { a_fields = PMap.empty; a_status = ref (EnumStatics e) }) p in
@@ -1692,7 +1668,7 @@ let type_generic_function ctx (e,cf) el ?(using_param=None) with_type p =
 		| WithTypeResume t -> (try unify_raise ctx ret t p with Error (Unify l,_) -> raise (WithTypeError(l,p)))
 		| _ -> ()
 	end;
-	let el,_ = unify_call_args ctx None el args ret p false in
+	let el,_ = unify_call_args ctx el args ret p false false in
 	let el = match using_param with None -> el | Some e -> e :: el in
 	(try
 		let gctx = Codegen.make_generic ctx cf.cf_params monos p in
@@ -1739,7 +1715,7 @@ let type_generic_function ctx (e,cf) el ?(using_param=None) with_type p =
 		in
 		let e = if stat then type_type ctx c.cl_path p else e in
 		let e = acc_get ctx (field_access ctx MCall cf2 (if stat then FStatic (c,cf2) else FInstance (c,[],cf2)) cf2.cf_type e p) p in (* TODO *)
-		(el,ret,e)
+		make_call ctx e el ret p
 	with Codegen.Generic_Exception (msg,p) ->
 		error msg p)
 
@@ -3218,7 +3194,8 @@ and type_expr ctx (e,p) (with_type:with_type) =
 		let unify_constructor_call c params f ct = match follow ct with
 			| TFun (args,r) ->
 				(try
-					fst (unify_call_args ctx (Some (TInst(c,params),f)) el args r p false)
+					let el,_,_ = unify_field_call ctx (FInstance(c,params,f)) el args r p false in
+					el
 				with Error (e,p) ->
 					display_error ctx (error_msg e) p;
 					[])
@@ -3742,9 +3719,10 @@ and type_call ctx e el (with_type:with_type) p =
 		| None -> error "Current class does not have a super" p
 		| Some (c,params) ->
 			let ct, f = get_constructor ctx c params p in
-			let el, _ = (match follow ct with
+			let el = (match follow ct with
 			| TFun (args,r) ->
-				unify_call_args ctx (Some (TInst(c,params),f)) el args r p false
+				let el,_,_ = unify_field_call ctx (FInstance(c,params,f)) el args r p false in
+				el
 			| _ ->
 				error "Constructor is not a function" p
 			) in
@@ -3755,11 +3733,6 @@ and type_call ctx e el (with_type:with_type) p =
 		def ()
 
 and build_call ctx acc el (with_type:with_type) p =
-	let fopts t f = match follow t with
-		| (TInst (c,pl) as t) -> Some (t,f)
-		| (TAnon a) as t -> (match !(a.a_status) with Statics c -> Some (TInst(c,List.map snd c.cl_params),f) | _ -> Some (t,f))
-		| _ -> None
-	in
 	let push_this e =
 		match e.eexpr with
 			| TConst (TInt _ | TFloat _ | TString _ | TBool _) ->
@@ -3771,19 +3744,19 @@ and build_call ctx acc el (with_type:with_type) p =
 	in
 	match acc with
 	| AKInline (ethis,f,fmode,t) when Meta.has Meta.Generic f.cf_meta ->
-		let el,t,e = type_generic_function ctx (ethis,f) el with_type p in
-		make_call ctx e el t p
+		type_generic_function ctx (ethis,f) el with_type p
 	| AKInline (ethis,f,fmode,t) ->
-		let params, tfunc = (match follow t with
-			| TFun (args,r) -> unify_call_args ctx (fopts ethis.etype f) el args r p true
-			| _ -> error (s_type (print_context()) t ^ " cannot be called") p
-		) in
-		make_call ctx (mk (TField (ethis,fmode)) t p) params (match tfunc with TFun(_,r) -> r | _ -> assert false) p
+		(match follow t with
+			| TFun (args,r) ->
+				let _,_,mk_call = unify_field_call ctx fmode el args r p true in
+				mk_call ethis
+			| _ ->
+				error (s_type (print_context()) t ^ " cannot be called") p
+		)
 	| AKUsing (et,cl,ef,eparam) when Meta.has Meta.Generic ef.cf_meta ->
 		(match et.eexpr with
 		| TField(ec,_) ->
-			let el,t,e = type_generic_function ctx (ec,ef) el ~using_param:(Some eparam) with_type p in
-			make_call ctx e el t p
+			type_generic_function ctx (ec,ef) el ~using_param:(Some eparam) with_type p
 		| _ -> assert false)
 	| AKUsing (et,cl,ef,eparam) ->
 		begin match ef.cf_kind with
@@ -3804,7 +3777,7 @@ and build_call ctx acc el (with_type:with_type) p =
 				| TFun ((_,_,t1) :: args,r) ->
 					unify ctx tthis t1 eparam.epos;
 					let ef = prepare_using_field ef in
-					begin match unify_call_args ctx (Some (TInst(cl,[]),ef)) el args r p (ef.cf_kind = Method MethInline) with
+					begin match unify_call_args ctx el args r p (ef.cf_kind = Method MethInline) (is_forced_inline (Some cl) ef) with
 					| el,TFun(args,r) -> el,args,r,(if is_abstract_impl_call then eparam else Codegen.AbstractCast.check_cast ctx t1 eparam eparam.epos)
 					| _ -> assert false
 					end
@@ -3869,36 +3842,39 @@ and build_call ctx acc el (with_type:with_type) p =
 	| AKExpr e ->
 		let rec loop t = match follow t with
 		| TFun (args,r) ->
-			let fopts = (match acc with
-				| AKExpr {eexpr = TField(e, (FStatic (_,f) | FInstance(_,_,f) | FAnon(f)))} ->
-					fopts e.etype f
-				| _ ->
-					None
-			) in
-			(match fopts,acc with
-				| Some (_,cf),AKExpr({eexpr = TField(e,_)}) when Meta.has Meta.Generic cf.cf_meta ->
-					type_generic_function ctx (e,cf) el with_type p
+			begin match e.eexpr with
+				| TField(e1,fa) when not (match fa with FEnum _ -> true | _ -> false) ->
+					begin match fa with
+						| FInstance(_,_,cf) | FStatic(_,cf) when Meta.has Meta.Generic cf.cf_meta ->
+							type_generic_function ctx (e1,cf) el with_type p
+						| _ ->
+							let _,_,mk_call = unify_field_call ctx fa el args r p false in
+							mk_call e1
+					end
 				| _ ->
-					let el, tfunc = unify_call_args ctx fopts el args r p false in
-					el,(match tfunc with TFun(_,r) -> r | _ -> assert false), {e with etype = tfunc})
+					let el, tfunc = unify_call_args ctx el args r p false false in
+					let r = match tfunc with TFun(_,r) -> r | _ -> assert false in
+					mk (TCall ({e with etype = tfunc},el)) r p
+			end
 		| TAbstract(a,tl) when Meta.has Meta.Callable a.a_meta ->
 			loop (Abstract.get_underlying_type a tl)
 		| TMono _ ->
 			let t = mk_mono() in
 			let el = List.map (fun e -> type_expr ctx e Value) el in
 			unify ctx (tfun (List.map (fun e -> e.etype) el) t) e.etype e.epos;
-			el, t, e
+			mk (TCall (e,el)) t p
 		| t ->
 			let el = List.map (fun e -> type_expr ctx e Value) el in
-			el, (if t == t_dynamic then
+			let t = if t == t_dynamic then
 				t_dynamic
 			else if ctx.untyped then
 				mk_mono()
 			else
-				error (s_type (print_context()) e.etype ^ " cannot be called") e.epos), e
+				error (s_type (print_context()) e.etype ^ " cannot be called") e.epos
+			in
+			mk (TCall (e,el)) t p
 		in
-		let el , t, e = loop e.etype in
-		mk (TCall (e,el)) t p
+		loop e.etype
 
 (* ---------------------------------------------------------------------- *)
 (* FINALIZATION *)
@@ -4580,7 +4556,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 			incr index;
 			(EArray ((EArrayDecl [e],p),(EConst (Int (string_of_int (!index))),p)),p)
 		) el in
-		let elt, _ = unify_call_args mctx (Some (TInst(mclass,[]),mfield)) constants (List.map fst eargs) t_dynamic p false in
+		let elt, _ = unify_call_args mctx constants (List.map fst eargs) t_dynamic p false false in
 		List.iter (fun f -> f()) (!todo);
 		List.map2 (fun (_,ise) e ->
 			let e, et = (match e.eexpr with
@@ -4667,7 +4643,7 @@ let type_macro ctx mode cpath f (el:Ast.expr list) p =
 
 let call_macro ctx path meth args p =
 	let mctx, (margs,_,mclass,mfield), call = load_macro ctx path meth p in
-	let el, _ = unify_call_args mctx (Some (TInst(mclass,[]),mfield)) args margs t_dynamic p false in
+	let el, _ = unify_call_args mctx args margs t_dynamic p false false in
 	call (List.map (fun e -> try Interp.make_const e with Exit -> error "Parameter should be a constant" e.epos) el)
 
 let call_init_macro ctx e =