Skip to content

Commit

Permalink
[typer] don't silently ignore error when loading macros in non-displa…
Browse files Browse the repository at this point in the history
…y mode

closes #10587
  • Loading branch information
Simn committed Feb 22, 2022
1 parent 4843d39 commit 71db0d8
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/typing/typeloadFields.ml
Original file line number Diff line number Diff line change
Expand Up @@ -753,28 +753,36 @@ module TypeBinding = struct
| TMono r -> (match r.tm_type with None -> false | Some t -> is_full_type t)
| TAbstract _ | TInst _ | TEnum _ | TLazy _ | TDynamic _ | TAnon _ | TType _ -> true
in
let force_macro () =
let force_macro display =
(* 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
let handle_display_field () =
if fctx.is_macro && not ctx.in_macro then
force_macro()
force_macro true
else begin
cf.cf_type <- TLazy r;
cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
end
in
if ctx.com.display.dms_full_typing then begin
if fctx.is_macro && not ctx.in_macro then
force_macro ()
force_macro false
else begin
cf.cf_type <- TLazy r;
(* is_lib ? *)
cctx.delayed_expr <- (ctx,Some r) :: cctx.delayed_expr;
end
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
if fctx.is_display_field then begin
handle_display_field()
Expand Down
3 changes: 3 additions & 0 deletions tests/misc/projects/Issue10587/Macro.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Macro {
public static macro function foo(e:Expr) {}
}
7 changes: 7 additions & 0 deletions tests/misc/projects/Issue10587/MainImport.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Macro;

class Main {
static function main() {
Macro.foo( 1 );
}
}
7 changes: 7 additions & 0 deletions tests/misc/projects/Issue10587/MainUsing.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using Macro;

class Main {
static function main() {
1.foo();
}
}
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue10587/compile-import-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--main MainImport
--interp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Macro.hx:2: characters 37-41 : Type not found : Expr
2 changes: 2 additions & 0 deletions tests/misc/projects/Issue10587/compile-using-fail.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--main MainUsing
--interp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Macro.hx:2: characters 37-41 : Type not found : Expr

2 comments on commit 71db0d8

@kLabz
Copy link
Contributor

@kLabz kLabz commented on 71db0d8 Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be helping with some very weird errors I'm having on macro heavy projects when I have issues in my code. Will this make it to 4.3.0?

@Simn
Copy link
Member Author

@Simn Simn commented on 71db0d8 Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, anything currently on development will be part of 4.3.0.

Please sign in to comment.