Skip to content

Commit 6f76d16

Browse files
authored
fix #34138, interpolation in async/spawn should ignore macros (#34154)
1 parent 8bd2eb1 commit 6f76d16

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

base/task.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ function _lift_one_interp!(e)
377377
end
378378
_lift_one_interp_helper(v, _, _) = v
379379
function _lift_one_interp_helper(expr::Expr, in_quote_context, letargs)
380-
if expr.head == :$
380+
if expr.head === :$
381381
if in_quote_context # This $ is simply interpolating out of the quote
382382
# Now, we're out of the quote, so any _further_ $ is ours.
383383
in_quote_context = false
@@ -386,8 +386,10 @@ function _lift_one_interp_helper(expr::Expr, in_quote_context, letargs)
386386
push!(letargs, :($(esc(newarg)) = $(esc(expr.args[1]))))
387387
return newarg # Don't recurse into the lifted $() exprs
388388
end
389-
elseif expr.head == :quote
389+
elseif expr.head === :quote
390390
in_quote_context = true # Don't try to lift $ directly out of quotes
391+
elseif expr.head === :macrocall
392+
return expr # Don't recur into macro calls, since some other macros use $
391393
end
392394
for (i,e) in enumerate(expr.args)
393395
expr.args[i] = _lift_one_interp_helper(e, in_quote_context, letargs)

test/threads_exec.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,3 +781,11 @@ end
781781
@test fetch(@async :($($a))) == a
782782
@test fetch(@async "$($a)") == "$a"
783783
end
784+
785+
# Issue #34138
786+
@testset "spawn interpolation: macrocalls" begin
787+
x = [reshape(1:4, 2, 2);]
788+
@test fetch(Threads.@spawn @. $exp(x)) == @. $exp(x)
789+
x = 2
790+
@test @eval(fetch(@async 2+$x)) == 4
791+
end

0 commit comments

Comments
 (0)