@@ -113,7 +113,7 @@ function Base.showerror(io::IO, exc::MacroExpansionError)
113113 highlight (io, src. file, byterange, note= exc. msg)
114114end
115115
116- function eval_macro_name (ctx:: MacroExpansionContext , ex:: SyntaxTree )
116+ function eval_macro_name (ctx:: MacroExpansionContext , mctx :: MacroContext , ex:: SyntaxTree )
117117 # `ex1` might contain a nontrivial mix of scope layers so we can't just
118118 # `eval()` it, as it's already been partially lowered by this point.
119119 # Instead, we repeat the latter parts of `lower()` here.
@@ -124,21 +124,25 @@ function eval_macro_name(ctx::MacroExpansionContext, ex::SyntaxTree)
124124 ctx5, ex5 = linearize_ir (ctx4, ex4)
125125 mod = ctx. current_layer. mod
126126 expr_form = to_lowered_expr (mod, ex5)
127- eval (mod, expr_form)
127+ try
128+ eval (mod, expr_form)
129+ catch
130+ throw (MacroExpansionError (mctx, ex, " Macro not found" , :all ))
131+ end
128132end
129133
130134function expand_macro (ctx:: MacroExpansionContext , ex:: SyntaxTree )
131135 @assert kind (ex) == K " macrocall"
132136
133137 macname = ex[1 ]
134- macfunc = eval_macro_name (ctx, macname)
138+ mctx = MacroContext (ctx. graph, ex, ctx. current_layer)
139+ macfunc = eval_macro_name (ctx, mctx, macname)
135140 # Macro call arguments may be either
136141 # * Unprocessed by the macro expansion pass
137142 # * Previously processed, but spliced into a further macro call emitted by
138143 # a macro expansion.
139144 # In either case, we need to set any unset scope layers before passing the
140145 # arguments to the macro call.
141- mctx = MacroContext (ctx. graph, ex, ctx. current_layer)
142146 macro_args = Any[mctx]
143147 for i in 2 : numchildren (ex)
144148 push! (macro_args, set_scope_layer (ctx, ex[i], ctx. current_layer. id, false ))
0 commit comments