Skip to content

Commit

Permalink
fix JuliaLang#37540, interpolation in quoted exprs returned from macr…
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Oct 16, 2020
1 parent 8407c59 commit 38afa5d
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ New language features
Language changes
----------------

* Macros that return `:quote` expressions (e.g. via `Expr(:quote, ...)`) were previously
able to work without escaping (`esc(...)`) their output when needed. This has been
corrected, and now `esc` must be used in these macros as it is in other macros ([#37540]).
* The `-->` operator now lowers to a `:call` expression, so it can be defined as
a function like other operators. The dotted version `.-->` is now parsed as well.
For backwards compatibility, `-->` still parses using its own expression head
Expand Down
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))))
return Expr(:escape, Expr(:call, GlobalRef(Core, :eval), __module__, Expr(:quote, ex)))
end
macro eval(mod, ex)
:(Core.eval($(esc(mod)), $(Expr(:quote,ex))))
return Expr(:escape, Expr(:call, GlobalRef(Core, :eval), mod, 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 @@ -1028,12 +1028,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, world);
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 @@ -2365,6 +2365,15 @@ end
# issue #37656
@test :(if true 'a' else 1 end) == Expr(:if, true, quote 'a' end, quote 1 end)

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

# issue #37890
struct A37890{A, B}
a
Expand Down

0 comments on commit 38afa5d

Please sign in to comment.