Skip to content

Commit

Permalink
fix #37540, interpolation in quoted exprs returned from macros
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Sep 14, 2020
1 parent 4c805d2 commit b35a823
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ Evaluate an expression with values interpolated into it using `eval`.
If two arguments are provided, the first is the module to evaluate in.
"""
macro eval(ex)
:(Core.eval($__module__, $(Expr(:quote,ex))))
:(Core.eval($__module__, $(Expr(:escape, Expr(:quote,ex)))))
end
macro eval(mod, ex)
:(Core.eval($(esc(mod)), $(Expr(:quote,ex))))
:(Core.eval($(esc(mod)), $(Expr(:escape, Expr(:quote,ex)))))
end

argtail(x, rest...) = rest
Expand Down
6 changes: 0 additions & 6 deletions src/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1017,12 +1017,6 @@ static jl_value_t *jl_expand_macros(jl_value_t *expr, jl_module_t *inmodule, str
if (e->head == quote_sym && jl_expr_nargs(e) == 1) {
expr = jl_call_scm_on_ast("julia-bq-macro", jl_exprarg(e, 0), inmodule);
JL_GC_PUSH1(&expr);
if (macroctx) {
// in a macro, `quote` also implies `escape`
jl_expr_t *e2 = jl_exprn(escape_sym, 1);
jl_array_ptr_set(e2->args, 0, expr);
expr = (jl_value_t*)e2;
}
expr = jl_expand_macros(expr, inmodule, macroctx, onelevel);
JL_GC_POP();
return expr;
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ macro everywhere(procs, ex)
imps = extract_imports(ex)
return quote
$(isempty(imps) ? nothing : Expr(:toplevel, imps...)) # run imports locally first
let ex = Expr(:toplevel, :(task_local_storage()[:SOURCE_PATH] = $(get(task_local_storage(), :SOURCE_PATH, nothing))), $(Expr(:quote, ex))),
let ex = Expr(:toplevel, :(task_local_storage()[:SOURCE_PATH] = $(get(task_local_storage(), :SOURCE_PATH, nothing))), $(esc(Expr(:quote, ex)))),
procs = $(esc(procs))
remotecall_eval(Main, procs, ex)
end
Expand Down
9 changes: 9 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2340,3 +2340,12 @@ if isodd(1) && all(iseven(2) for c in ())
else
@test false
end

# issue #37540
macro m37540()
quote
x = 1
:($x)
end
end
@test @m37540() == 1

0 comments on commit b35a823

Please sign in to comment.