Skip to content

Commit caa35be

Browse files
committed
fixups
1 parent 4c98ae0 commit caa35be

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

base/methodshow.jl

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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{Union{Function, Nothing}}(nothing)
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 = 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
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(string(file), normpath(Sys.BUILD_STDLIB_PATH) => normpath(Sys.STDLIB))
131138
end
132-
return Symbol(file), line
139+
return string(file), line
133140
end
134141

135142
functionloc(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
214218
end
@@ -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
418411
end

test/show.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ else
637637
end
638638

639639
# Method location correction (Revise integration)
640-
methloc = Base.methodloc_callback[]
641640
dummyloc(m::Method) = :nofile, 123456789
642641
Base.methodloc_callback[] = dummyloc
643642
let repr = sprint(show, "text/plain", methods(Base.inbase))
@@ -646,7 +645,7 @@ end
646645
let repr = sprint(show, "text/html", methods(Base.inbase))
647646
@test occursin("nofile:123456789", repr)
648647
end
649-
Base.methodloc_callback[] = methloc
648+
Base.methodloc_callback[] = nothing
650649

651650
@testset "matrix printing" begin
652651
# print_matrix should be able to handle small and large objects easily, test by

0 commit comments

Comments
 (0)