Jelajahi Sumber

"bugfix": promote first argument to ExprOf<a_this> if method is a macro and handle call accordingly

Simon Krajewski 12 tahun lalu
induk
melakukan
be97c4a467
2 mengubah file dengan 6 tambahan dan 2 penghapusan
  1. 5 1
      typeload.ml
  2. 1 1
      typer.ml

+ 5 - 1
typeload.ml

@@ -161,7 +161,11 @@ let make_module ctx mpath file tdecls loadp =
 						{ f with cff_name = "_new"; cff_access = AStatic :: f.cff_access; cff_kind = FFun fu; cff_meta = (Meta.Impl,[],p) :: f.cff_meta }
 					| FFun fu when not stat ->
 						if Meta.has Meta.From f.cff_meta then error "@:from cast functions must be static" f.cff_pos;
-						let fu = { fu with f_args = ("this",false,Some this_t,None) :: fu.f_args } in
+						let first = if List.mem AMacro f.cff_access
+							then CTPath ({ tpackage = ["haxe";"macro"]; tname = "Expr"; tsub = Some ("ExprOf"); tparams = [TPType this_t] })
+							else this_t
+						in
+						let fu = { fu with f_args = ("this",false,Some first,None) :: fu.f_args } in
 						{ f with cff_kind = FFun fu; cff_access = AStatic :: f.cff_access; cff_meta = (Meta.Impl,[],p) :: f.cff_meta }
 					| _ ->
 						f

+ 1 - 1
typer.ml

@@ -1215,7 +1215,7 @@ and type_field ctx e i p mode =
 				let t = field_type f in
 				begin match follow t with
 					| TFun((_,_,t1) :: _,_) ->
-						unify ctx (apply_params a.a_types pl a.a_this) t1 p
+						(match f.cf_kind with Method MethMacro -> () | _ -> unify ctx (apply_params a.a_types pl a.a_this) t1 p)
 					| _ ->
 						error (i ^ " cannot be called") p
 				end;