Skip to content

Commit 04ca3ce

Browse files
committed
fix some internals being called
1 parent d995391 commit 04ca3ce

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/internals.jl

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Base.schedule(t, val; error=false) = (schedule(t.t, val; error); t)
2828
macro spawn(ex)
2929
tp = QuoteNode(:default)
3030

31-
letargs = Base._lift_one_interp!(ex)
31+
letargs = _lift_one_interp!(ex)
3232

33-
thunk = Base.replace_linenums!(:(()->($(esc(ex)))), __source__)
33+
thunk = replace_linenums!(:(()->($(esc(ex)))), __source__)
3434
var = esc(Base.sync_varname) # This is for the @sync macro which sets a local variable whose name is
3535
# the symbol bound to Base.sync_varname
3636
# I asked on slack and this is apparently safe to consider a public API
@@ -80,4 +80,25 @@ function _lift_one_interp_helper(expr::Expr, in_quote_context, letargs)
8080
expr
8181
end
8282

83+
# Copied from base rather than calling it directly because who knows if it'll change in the future
84+
replace_linenums!(ex, ln::LineNumberNode) = ex
85+
function replace_linenums!(ex::Expr, ln::LineNumberNode)
86+
if ex.head === :block || ex.head === :quote
87+
# replace line number expressions from metadata (not argument literal or inert) position
88+
map!(ex.args, ex.args) do @nospecialize(x)
89+
isa(x, Expr) && x.head === :line && length(x.args) == 1 && return Expr(:line, ln.line)
90+
isa(x, Expr) && x.head === :line && length(x.args) == 2 && return Expr(:line, ln.line, ln.file)
91+
isa(x, LineNumberNode) && return ln
92+
return x
93+
end
94+
end
95+
# preserve any linenums inside `esc(...)` guards
96+
if ex.head !== :escape
97+
for subex in ex.args
98+
subex isa Expr && replace_linenums!(subex, ln)
99+
end
100+
end
101+
return ex
102+
end
103+
83104
end # module Internals

0 commit comments

Comments
 (0)