@@ -136,6 +136,31 @@ function LinearAlgebra.LAPACK.trsyl!(transa, transb, A, B, C::AbstractThunk, isg
136
136
return throw (MutateThunkException ())
137
137
end
138
138
139
+
140
+ @static if VERSION > v " 1.10"
141
+ using Base: replace_linenums!
142
+ else
143
+ replace_linenums! (ex, ln:: LineNumberNode ) = ex
144
+ function replace_linenums! (ex:: Expr , ln:: LineNumberNode )
145
+ if ex. head === :block || ex. head === :quote
146
+ # replace line number expressions from metadata (not argument literal or inert) position
147
+ map! (ex. args, ex. args) do @nospecialize (x)
148
+ isa (x, Expr) && x. head === :line && length (x. args) == 1 && return Expr (:line , ln. line)
149
+ isa (x, Expr) && x. head === :line && length (x. args) == 2 && return Expr (:line , ln. line, ln. file)
150
+ isa (x, LineNumberNode) && return ln
151
+ return x
152
+ end
153
+ end
154
+ # preserve any linenums inside `esc(...)` guards
155
+ if ex. head != = :escape
156
+ for subex in ex. args
157
+ subex isa Expr && replace_linenums! (subex, ln)
158
+ end
159
+ end
160
+ return ex
161
+ end
162
+ end
163
+
139
164
"""
140
165
@thunk expr
141
166
@@ -145,7 +170,7 @@ macro thunk(body)
145
170
# Basically `:(Thunk(() -> $(esc(body))))` but use the location where it is defined.
146
171
# so we get useful stack traces if it errors.
147
172
letargs = Base. _lift_one_interp! (body)
148
- func = Base . replace_linenums! (:(()-> ($ (esc (body)))), __source__)
173
+ func = replace_linenums! (:(()-> ($ (esc (body)))), __source__)
149
174
return quote
150
175
if _usethunks ()
151
176
let $ (letargs... )
0 commit comments