瀏覽代碼

resolved an issue with resolving the @:resolve resolver

Simon Krajewski 13 年之前
父節點
當前提交
8921764718
共有 2 個文件被更改,包括 13 次插入15 次删除
  1. 7 7
      typeload.ml
  2. 6 8
      typer.ml

+ 7 - 7
typeload.ml

@@ -759,6 +759,12 @@ let patch_class ctx c fields =
 		in
 		List.rev (loop [] fields)
 
+let rec string_list_of_expr_path (e,p) = 
+	match e with
+	| EConst (Ident i) -> [i]
+	| EField (e,f) -> f :: string_list_of_expr_path e
+	| _ -> error "Invalid path" p
+
 let build_module_def ctx mt meta fvars fbuild =
 	let rec loop = function
 		| (":build",args,p) :: l ->
@@ -766,13 +772,7 @@ let build_module_def ctx mt meta fvars fbuild =
 				| [ECall (epath,el),p] -> epath, el
 				| _ -> error "Invalid build parameters" p
 			) in
-			let rec getpath (e,p) =
-				match e with
-				| EConst (Ident i) -> [i]
-				| EField (e,f) -> f :: getpath e
-				| _ -> error "Build call parameter must be a class path" p
-			in
-			let s = String.concat "." (List.rev (getpath epath)) in
+			let s = try String.concat "." (List.rev (string_list_of_expr_path epath)) with Error (_,p) -> error "Build call parameter must be a class path" p in
 			if ctx.in_macro then error "You cannot used :build inside a macro : make sure that your enum is not used in macro" p;
 			let old = ctx.g.get_build_infos in
 			ctx.g.get_build_infos <- (fun() -> Some (mt, fvars()));

+ 6 - 8
typer.ml

@@ -703,17 +703,15 @@ let rec type_field ctx e i p mode =
 			(* if any class in the tree has @:resolve metadata, call the corresponding macro *)
 			let rec loop c =
 				try
-					let er = match List.filter (fun (m,_,_) -> m = ":resolve") c.cl_meta with
+					let epath = match List.filter (fun (m,_,_) -> m = ":resolve") c.cl_meta with
 						| [] -> raise Not_found
-						| (_,[(EField(ef,v),_)],_) :: [] -> type_expr ctx ef true,v
+						| (_,[e],_) :: [] -> Typeload.string_list_of_expr_path e
 						| _ -> error ("Argument to @:resolve must be a Expr->String->Expr macro") c.cl_pos
 					in
-					(match (fst er).eexpr with
-						| TTypeExpr (TClassDecl c) ->
-							(match ctx.g.do_macro ctx MExpr c.cl_path (snd er) [Interp.make_ast e;EConst (String i),p] p with
-							| Some e -> AKExpr (type_expr ctx e true)
-							| None -> raise Not_found)
-						| _ -> error ("Argument to @:resolve must be a Expr->String->Expr macro") (fst er).epos);
+					let s = String.concat "." (List.rev epath) in
+					(match Typeload.apply_macro ctx MExpr s [Interp.make_ast e;EConst (String i),p] p with
+					| Some e -> AKExpr (type_expr ctx e true)
+					| None -> raise Not_found)
 				with Not_found ->
 					(match c.cl_super with None -> raise Not_found | Some (csup,_) -> loop csup)
 			in