From f0881ef625712727d44ac9645b6cb66660d6cb70 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 16 Jun 2023 22:38:00 +0000 Subject: [PATCH 1/2] Pass through world age for kwargs MethodError Fixes #50200 --- base/errorshow.jl | 2 +- test/errorshow.jl | 27 ++++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/base/errorshow.jl b/base/errorshow.jl index 176cae4b5251a..4d32743f1af52 100644 --- a/base/errorshow.jl +++ b/base/errorshow.jl @@ -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 diff --git a/test/errorshow.jl b/test/errorshow.jl index 9be3e675cede3..404b8e6843a83 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -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 @@ -620,6 +620,31 @@ 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)) + 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) From 18dd7a2d282a36cd672ec48b59bc7b0a959028c2 Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Fri, 16 Jun 2023 22:50:28 +0000 Subject: [PATCH 2/2] Don't color Any... red if the method actually matched Fixes the drive-by observation I made in #50200. --- base/errorshow.jl | 6 +++++- test/errorshow.jl | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/base/errorshow.jl b/base/errorshow.jl index 4d32743f1af52..24bd3a37d5298 100644 --- a/base/errorshow.jl +++ b/base/errorshow.jl @@ -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...) diff --git a/test/errorshow.jl b/test/errorshow.jl index 404b8e6843a83..28ae3fd32365a 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -627,6 +627,7 @@ using Base.Experimental: @opaque 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