浏览代码

automatically add `@:astSource` if we have CoreApi defined

Simon Krajewski 9 年之前
父节点
当前提交
f66053a5db
共有 1 个文件被更改,包括 8 次插入4 次删除
  1. 8 4
      typeload.ml

+ 8 - 4
typeload.ml

@@ -2441,10 +2441,14 @@ module ClassInitializer = struct
 			cf_params = params;
 			cf_params = params;
 			cf_overloads = [];
 			cf_overloads = [];
 		} in
 		} in
-		cf.cf_meta <- List.map (fun (m,el,p) -> match m,el with
-			| Meta.AstSource,[] -> (m,(match fd.f_expr with None -> [] | Some e -> [e]),p)
-			| _ -> m,el,p
-		) cf.cf_meta;
+		let rec loop meta =
+			let ast_source () = (Meta.AstSource,(match fd.f_expr with None -> [] | Some e -> [e]),p) in
+			match meta with
+			| (Meta.AstSource,[],_) :: meta -> (ast_source()) :: meta
+			| m :: meta -> m :: loop meta
+			| [] -> if defined ctx.com Define.CoreApi then [ast_source()] else []
+		in
+		cf.cf_meta <- loop cf.cf_meta;
 		generate_value_meta ctx.com (Some c) cf fd.f_args;
 		generate_value_meta ctx.com (Some c) cf fd.f_args;
 		check_abstract (ctx,cctx,fctx) c cf fd t ret p;
 		check_abstract (ctx,cctx,fctx) c cf fd t ret p;
 		init_meta_overloads ctx (Some c) cf;
 		init_meta_overloads ctx (Some c) cf;