Skip to content

Commit

Permalink
Merge pull request #50201 from JuliaLang/kf/metherrworldage
Browse files Browse the repository at this point in the history
Pass through world age for kwargs MethodError
  • Loading branch information
Keno authored Jun 18, 2023
2 parents 65523e4 + 18dd7a2 commit 9501540
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
8 changes: 6 additions & 2 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function showerror(io::IO, ex::MethodError)
ft = typeof(f)
arg_types_param = arg_types_param[3:end]
kwargs = pairs(ex.args[1])
ex = MethodError(f, ex.args[3:end::Int])
ex = MethodError(f, ex.args[3:end::Int], ex.world)
end
name = ft.name.mt.name
if f === Base.convert && length(arg_types_param) == 2 && !is_arg_types
Expand Down Expand Up @@ -490,7 +490,11 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
if !((min(length(t_i), length(sig)) == 0) && k==1)
print(iob, ", ")
end
if get(io, :color, false)::Bool
if k == 1 && Base.isvarargtype(sigtype)
# There wasn't actually a mismatch - the method match failed for
# some other reason, e.g. world age. Just print the sigstr.
print(iob, sigstr...)
elseif get(io, :color, false)::Bool
let sigstr=sigstr
Base.with_output_color(Base.error_color(), iob) do iob
print(iob, "::", sigstr...)
Expand Down
28 changes: 27 additions & 1 deletion test/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ let
end
end

@testset "show for manually thrown MethodError" begin
@testset "show for MethodError with world age issue" begin
global f21006

f21006() = nothing
Expand Down Expand Up @@ -620,6 +620,32 @@ end
end
end

# Issue #50200
using Base.Experimental: @opaque
@testset "show for MethodError with world age issue (kwarg)" begin
test_no_error(f) = @test f() === nothing
function test_worldage_error(f)
ex = try; f(); error("Should not have been reached") catch ex; ex; end
@test occursin("The applicable method may be too new", sprint(Base.showerror, ex))
@test !occursin("!Matched::", sprint(Base.showerror, ex))
end

global callback50200

# First the no-kwargs version
callback50200 = (args...)->nothing
f = @opaque ()->callback50200()
test_no_error(f)
callback50200 = (args...)->nothing
test_worldage_error(f)

callback50200 = (args...; kwargs...)->nothing
f = @opaque ()->callback50200(;a=1)
test_no_error(f)
callback50200 = (args...; kwargs...)->nothing
test_worldage_error(f)
end

# Custom hints
struct HasNoOne end
function recommend_oneunit(io, ex, arg_types, kwargs)
Expand Down

2 comments on commit 9501540

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your package evaluation job has completed - possible new issues were detected.
A full report can be found here.

Please sign in to comment.