@@ -119,17 +119,24 @@ end
119119# In case the line numbers in the source code have changed since the code was compiled,
120120# allow packages to set a callback function that corrects them.
121121# (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 {Function} ()
124123
125124# 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 = string (m. file), m. line
127+ if isassigned (methodloc_callback)
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
129136 # BUILD_STDLIB_PATH gets defined in sysinfo.jl
130- file = replace (String ( file) , normpath (Sys. BUILD_STDLIB_PATH) => normpath (Sys. STDLIB))
137+ file = replace (file, normpath (Sys. BUILD_STDLIB_PATH) => normpath (Sys. STDLIB))
131138 end
132- return Symbol ( file) , line
139+ return file, line
133140end
134141
135142functionloc (m:: Core.MethodInstance ) = functionloc (m. def)
@@ -205,10 +212,7 @@ function show(io::IO, m::Method)
205212 show_method_params (io, tv)
206213 print (io, " in " , m. module)
207214 if line > 0
208- try
209- file, line = updated_methodloc (m)
210- catch
211- end
215+ file, line = updated_methodloc (m)
212216 print (io, " at " , file, " :" , line)
213217 end
214218end
@@ -257,11 +261,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru
257261 println (io)
258262 print (io, " [$(n) ] " )
259263 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)
265265 push! (LAST_SHOWN_LINE_INFOS, (string (file), line))
266266 else
267267 rest += 1
@@ -371,10 +371,7 @@ function show(io::IO, ::MIME"text/html", m::Method)
371371 end
372372 print (io, " in " , m. module)
373373 if line > 0
374- try
375- file, line = updated_methodloc (m)
376- catch
377- end
374+ file, line = updated_methodloc (m)
378375 u = url (m)
379376 if isempty (u)
380377 print (io, " at " , file, " :" , line)
@@ -408,11 +405,7 @@ function show(io::IO, mime::MIME"text/plain", mt::AbstractVector{Method})
408405 first = false
409406 print (io, " [$(i) ] " )
410407 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)
416409 push! (LAST_SHOWN_LINE_INFOS, (string (file), line))
417410 end
418411end
0 commit comments