ソースを参照

[macro] check macro deprecation upon a call instead of upon loading it (fixes #9425)

Aleksandr Kuzmenko 5 年 前
コミット
98623c2d97

+ 1 - 0
src/typing/calls.ml

@@ -666,6 +666,7 @@ let rec build_call ?(mode=MGet) ctx acc el (with_type:WithType.t) p =
 		let ethis_f = ref (fun () -> ()) in
 		let f = (match ethis.eexpr with
 		| TTypeExpr (TClassDecl c) ->
+			DeprecationCheck.check_cf ctx.com cf p;
 			(match ctx.g.do_macro ctx MExpr c.cl_path cf.cf_name el p with
 			| None -> (fun() -> type_expr ~mode ctx (EConst (Ident "null"),p) WithType.value)
 			| Some (EMeta((Meta.MergeBlock,_,_),(EBlock el,_)),_) -> (fun () -> let e = (!type_block_ref) ctx el with_type p in mk (TMeta((Meta.MergeBlock,[],p), e)) e.etype e.epos)

+ 0 - 1
src/typing/macroContext.ml

@@ -560,7 +560,6 @@ let load_macro' ctx display cpath f p =
 				| _ -> error "Macro should be called on a class" p
 		in
 		api.MacroApi.current_macro_module <- (fun() -> mloaded);
-		DeprecationCheck.check_cf mctx.com meth p;
 		let meth = (match follow meth.cf_type with TFun (args,ret) -> (args,ret,cl,meth),mloaded | _ -> error "Macro call should be a method" p) in
 		restore();
 		if not ctx.in_macro then flush_macro_context mint ctx;

+ 12 - 0
tests/misc/projects/Issue9425/Main.hx

@@ -0,0 +1,12 @@
+class Test {
+	@:deprecated
+	public static macro function test() {
+		return macro {};
+	}
+}
+
+class Main {
+	public static function main() {
+		Test.test();
+	}
+}

+ 1 - 0
tests/misc/projects/Issue9425/compile-success.hxml

@@ -0,0 +1 @@
+--run Main

+ 1 - 0
tests/misc/projects/Issue9425/compile-success.hxml.stderr

@@ -0,0 +1 @@
+Main.hx:10: characters 3-14 : Warning : Usage of this field is deprecated