Skip to content

Commit

Permalink
make MethodError for unhandled kwarg more accurate (JuliaLang#53500)
Browse files Browse the repository at this point in the history
Previously it threw this error manually, so it did not have the world
info for this lookup and message to be fully accurate.
  • Loading branch information
vtjnash authored Mar 4, 2024
1 parent 688ae0a commit f66fd47
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ end
## keyword arg lowering generates calls to this ##
function kwerr(kw, args::Vararg{Any,N}) where {N}
@noinline
throw(MethodError(Core.kwcall, (kw, args...)))
throw(MethodError(Core.kwcall, (kw, args...), tls_world_age()))
end

## system error handling ##
Expand Down
5 changes: 3 additions & 2 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,11 @@ function showerror(io::IO, ex::MethodError)
end
end
if ex.world == typemax(UInt) || hasmethod(f, arg_types, world=ex.world)
if !isempty(kwargs)
print(io, "\nThis method does not support all of the given keyword arguments (and may not support any).")
end
if ex.world == typemax(UInt) || isempty(kwargs)
print(io, "\nThis error has been manually thrown, explicitly, so the method may exist but be intentionally marked as unimplemented.")
else
print(io, "\nThis method may not support any keyword arguments.")
end
elseif hasmethod(f, arg_types) && !hasmethod(f, arg_types, world=ex.world)
curworld = get_world_counter()
Expand Down
2 changes: 1 addition & 1 deletion test/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ end

str = sprint(Base.showerror, MethodError(Core.kwcall, ((; a=3.0), +, 1.0, 2.0), Base.get_world_counter()))
@test startswith(str, "MethodError: no method matching +(::Float64, ::Float64; a::Float64)")
@test occursin("This method may not support any keyword arguments", str)
@test occursin("This method does not support all of the given keyword arguments", str)

@test_throws "MethodError: no method matching kwcall()" Core.kwcall()
end
Expand Down

0 comments on commit f66fd47

Please sign in to comment.