Browse Source

[typer] don't silently ignore error when loading macros in non-display mode

closes #10587
Simon Krajewski 3 years ago
parent
commit
71db0d80c4

+ 13 - 5
src/typing/typeloadFields.ml

@@ -753,13 +753,21 @@ module TypeBinding = struct
 			| TMono r -> (match r.tm_type with None -> false | Some t -> is_full_type t)
 			| TMono r -> (match r.tm_type with None -> false | Some t -> is_full_type t)
 			| TAbstract _ | TInst _ | TEnum _ | TLazy _ | TDynamic _ | TAnon _ | TType _ -> true
 			| TAbstract _ | TInst _ | TEnum _ | TLazy _ | TDynamic _ | TAnon _ | TType _ -> true
 		in
 		in
-		let force_macro () =
+		let force_macro display =
 			(* force macro system loading of this class in order to get completion *)
 			(* force macro system loading of this class in order to get completion *)
-			delay ctx PTypeField (fun() -> try ignore(ctx.g.do_macro ctx MDisplay c.cl_path cf.cf_name [] p) with Exit | Error _ -> ())
+			delay ctx PTypeField (fun() ->
+				try
+					ignore(ctx.g.do_macro ctx MDisplay c.cl_path cf.cf_name [] p)
+				with
+				| Exit ->
+					()
+				| Error _ when display ->
+					()
+			)
 		in
 		in
 		let handle_display_field () =
 		let handle_display_field () =
 			if fctx.is_macro && not ctx.in_macro then
 			if fctx.is_macro && not ctx.in_macro then
-				force_macro()
+				force_macro true
 			else begin
 			else begin
 				cf.cf_type <- TLazy r;
 				cf.cf_type <- TLazy r;
 				cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
 				cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
@@ -767,14 +775,14 @@ module TypeBinding = struct
 		in
 		in
 		if ctx.com.display.dms_full_typing then begin
 		if ctx.com.display.dms_full_typing then begin
 			if fctx.is_macro && not ctx.in_macro then
 			if fctx.is_macro && not ctx.in_macro then
-				force_macro ()
+				force_macro false
 			else begin
 			else begin
 				cf.cf_type <- TLazy r;
 				cf.cf_type <- TLazy r;
 				(* is_lib ? *)
 				(* is_lib ? *)
 				cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
 				cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
 			end
 			end
 		end else if ctx.com.display.dms_force_macro_typing && fctx.is_macro && not ctx.in_macro then
 		end else if ctx.com.display.dms_force_macro_typing && fctx.is_macro && not ctx.in_macro then
-			force_macro()
+			force_macro true
 		else begin
 		else begin
 			if fctx.is_display_field then begin
 			if fctx.is_display_field then begin
 				handle_display_field()
 				handle_display_field()

+ 3 - 0
tests/misc/projects/Issue10587/Macro.hx

@@ -0,0 +1,3 @@
+class Macro {
+	public static macro function foo(e:Expr) {}
+}

+ 7 - 0
tests/misc/projects/Issue10587/MainImport.hx

@@ -0,0 +1,7 @@
+import Macro;
+
+class Main {
+	static function main() {
+		Macro.foo( 1 );
+	}
+}

+ 7 - 0
tests/misc/projects/Issue10587/MainUsing.hx

@@ -0,0 +1,7 @@
+using Macro;
+
+class Main {
+	static function main() {
+		1.foo();
+	}
+}

+ 2 - 0
tests/misc/projects/Issue10587/compile-import-fail.hxml

@@ -0,0 +1,2 @@
+--main MainImport
+--interp

+ 1 - 0
tests/misc/projects/Issue10587/compile-import-fail.hxml.stderr

@@ -0,0 +1 @@
+Macro.hx:2: characters 37-41 : Type not found : Expr

+ 2 - 0
tests/misc/projects/Issue10587/compile-using-fail.hxml

@@ -0,0 +1,2 @@
+--main MainUsing
+--interp

+ 1 - 0
tests/misc/projects/Issue10587/compile-using-fail.hxml.stderr

@@ -0,0 +1 @@
+Macro.hx:2: characters 37-41 : Type not found : Expr