@@ -119,17 +119,24 @@ end
119
119
# In case the line numbers in the source code have changed since the code was compiled,
120
120
# allow packages to set a callback function that corrects them.
121
121
# (Used by Revise and perhaps other packages.)
122
- default_methodloc (method:: Method ) = method. file, method. line
123
- const methodloc_callback = Ref {Function} (default_methodloc)
122
+ const methodloc_callback = Ref {Union{Function, Nothing}} (nothing )
124
123
125
124
# This function does the method location updating
126
- function updated_methodloc (m)
127
- file, line = invokelatest (methodloc_callback[], m)
128
- if file != = nothing && isdefined (@__MODULE__ , :Sys )
125
+ function updated_methodloc (m:: Method ):: Tuple{String, Int32}
126
+ file, line = m. file, m. line
127
+ if methodloc_callback[] != = nothing
128
+ try
129
+ file, line = invokelatest (methodloc_callback[], m)
130
+ catch
131
+ end
132
+ end
133
+ # The file defining Base.Sys gets included after this file is included so make sure
134
+ # this function is valid even in this intermediary state
135
+ if isdefined (@__MODULE__ , :Sys ) && Sys. BUILD_STDLIB_PATH != Sys. STDLIB
129
136
# BUILD_STDLIB_PATH gets defined in sysinfo.jl
130
- file = replace (String (file), normpath (Sys. BUILD_STDLIB_PATH) => normpath (Sys. STDLIB))
137
+ file = replace (string (file), normpath (Sys. BUILD_STDLIB_PATH) => normpath (Sys. STDLIB))
131
138
end
132
- return Symbol (file), line
139
+ return string (file), line
133
140
end
134
141
135
142
functionloc (m:: Core.MethodInstance ) = functionloc (m. def)
@@ -205,10 +212,7 @@ function show(io::IO, m::Method)
205
212
show_method_params (io, tv)
206
213
print (io, " in " , m. module)
207
214
if line > 0
208
- try
209
- file, line = updated_methodloc (m)
210
- catch
211
- end
215
+ file, line = updated_methodloc (m)
212
216
print (io, " at " , file, " :" , line)
213
217
end
214
218
end
@@ -257,11 +261,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru
257
261
println (io)
258
262
print (io, " [$(n) ] " )
259
263
show (io, meth)
260
- file, line = meth. file, meth. line
261
- try
262
- file, line = updated_methodloc (m)
263
- catch
264
- end
264
+ file, line = updated_methodloc (meth)
265
265
push! (LAST_SHOWN_LINE_INFOS, (string (file), line))
266
266
else
267
267
rest += 1
@@ -371,10 +371,7 @@ function show(io::IO, ::MIME"text/html", m::Method)
371
371
end
372
372
print (io, " in " , m. module)
373
373
if line > 0
374
- try
375
- file, line = updated_methodloc (m)
376
- catch
377
- end
374
+ file, line = updated_methodloc (m)
378
375
u = url (m)
379
376
if isempty (u)
380
377
print (io, " at " , file, " :" , line)
@@ -408,11 +405,7 @@ function show(io::IO, mime::MIME"text/plain", mt::AbstractVector{Method})
408
405
first = false
409
406
print (io, " [$(i) ] " )
410
407
show (io, m)
411
- file, line = m. file, m. line
412
- try
413
- file, line = updated_methodloc (m)
414
- catch
415
- end
408
+ file, line = updated_methodloc (m)
416
409
push! (LAST_SHOWN_LINE_INFOS, (string (file), line))
417
410
end
418
411
end
0 commit comments