Skip to content

Commit 6d2fbaf

Browse files
rejigger the code to compute the method instance in stacktraces (#563)
* rejigger the code to compute the method instance in stacktraces this works around a bug that occurs when there is an undefined sparams --------- Co-authored-by: Shuhei Kadowaki <[email protected]>
1 parent b2ebd69 commit 6d2fbaf

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/utils.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,10 @@ function Base.StackTraces.StackFrame(frame::Frame)
735735
if scope isa Method
736736
method = scope
737737
method_args = [something(frame.framedata.locals[i]) for i in 1:method.nargs]
738-
atypes = Tuple{mapany(_Typeof, method_args)...}
738+
argt = Tuple{mapany(_Typeof, method_args)...}
739739
sig = method.sig
740-
sparams = Core.svec(frame.framedata.sparams...)
741-
mi = Core.Compiler.specialize_method(method, atypes, sparams)
740+
atype, sparams = ccall(:jl_type_intersection_with_env, Any, (Any, Any), argt, sig)::SimpleVector
741+
mi = Core.Compiler.specialize_method(method, atype, sparams::SimpleVector)
742742
fname = method.name
743743
else
744744
mi = frame.framecode.src

test/interpret.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,17 @@ finally
565565
break_off(:error)
566566
end
567567

568+
f_562(x::Union{Vector{T}, Nothing}) where {T} = x + 1
569+
try
570+
break_on(:error)
571+
local frame, bp = @interpret f_562(nothing)
572+
573+
stacktrace_lines = split(sprint(Base.display_error, bp.err, leaf(frame)), '\n')
574+
@test stacktrace_lines[1] == "ERROR: MethodError: no method matching +(::Nothing, ::Int64)"
575+
finally
576+
break_off(:error)
577+
end
578+
568579
# https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/154
569580
q = QuoteNode([1])
570581
@test @interpret deepcopy(q) == q

0 commit comments

Comments
 (0)