2
0
Эх сурвалжийг харах

support for using macro functions within other macros (fixed issue #584)

Simon Krajewski 13 жил өмнө
parent
commit
399b576c58
1 өөрчлөгдсөн 10 нэмэгдсэн , 4 устгасан
  1. 10 4
      typer.ml

+ 10 - 4
typer.ml

@@ -432,7 +432,12 @@ let using_field ctx mode e i p =
 				let t = field_type f in
 				(match follow t with
 				| TFun ((_,_,t0) :: args,r) ->
-					(try unify_raise ctx e.etype t0 p with Error (Unify _,_) -> raise Not_found);
+					let t0 = (try match t0 with
+					| TType({t_path=["haxe";"macro"], ("ExprOf"|"ExprRequire")}, [t]) ->
+						(try unify_raise ctx e.etype t p with Error (Unify _,_) -> raise Not_found); t;
+					| _ -> raise Not_found
+					with Not_found ->
+						(try unify_raise ctx e.etype t0 p with Error (Unify _,_) -> raise Not_found); t0) in
 					if follow e.etype == t_dynamic && follow t0 != t_dynamic then raise Not_found;
 					let et = type_module_type ctx (TClassDecl c) None p in
 					AKUsing (mk (TField (et,i)) t p,f,e)
@@ -1775,6 +1780,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 					List.iter (fun f ->
 						let f = { f with cf_type = opt_type f.cf_type } in
 						match follow (field_type f) with
+						| TFun((_,_,TType({t_path=["haxe";"macro"], ("ExprOf"|"ExprRequire")}, [t])) :: args, ret)
 						| TFun ((_,_,t) :: args, ret) when (try unify_raise ctx (dup e.etype) t e.epos; true with _ -> false) ->
 							let f = { f with cf_type = TFun (args,ret); cf_params = [] } in
 							if follow e.etype == t_dynamic && follow t != t_dynamic then
@@ -2433,7 +2439,7 @@ let make_macro_api ctx p =
 			if ismacro then
 				m.m_extra.m_macro_calls <- file :: List.filter ((<>) file) m.m_extra.m_macro_calls
 			else
-				add_dependency m (create_fake_module ctx file);
+				add_dependency m (create_fake_module ctx file);
 		);
 		Interp.current_module = (fun() ->
 			ctx.current
@@ -2727,8 +2733,8 @@ let rec create com =
 						let r = ref (fun() -> assert false) in
 						r := (fun() ->
 							let t = (if not (is_nullable t) then TType (td,[t]) else t) in
-							r := (fun() -> t);
-							t
+							r := (fun() -> t);
+							t
 						);
 						TLazy r
 				in