Skip to content

Commit 9ef7b97

Browse files
authored
Fix eval_macro_name into closed modules during precompilation (#82)
1 parent edf03df commit 9ef7b97

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/macro_expansion.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,13 @@ function eval_macro_name(ctx::MacroExpansionContext, mctx::MacroContext, ex::Syn
149149
mod = current_layer(ctx).mod
150150
expr_form = to_lowered_expr(ex5)
151151
try
152-
Core.eval(mod, expr_form)
152+
# Using Core.eval here fails when precompiling packages since we hit the
153+
# user-facing error (in `jl_check_top_level_effect`) that warns that
154+
# effects won't persist when eval-ing into a closed module.
155+
# `jl_invoke_julia_macro` bypasses this by calling `jl_toplevel_eval` on
156+
# the macro name. This is fine assuming the first argument to the
157+
# macrocall is effect-free.
158+
ccall(:jl_toplevel_eval, Any, (Any, Any), mod, expr_form)
153159
catch err
154160
throw(MacroExpansionError(mctx, ex, "Macro not found", :all, err))
155161
end

0 commit comments

Comments
 (0)