Skip to content

Commit f66fd47

Browse files
authored
make MethodError for unhandled kwarg more accurate (JuliaLang#53500)
Previously it threw this error manually, so it did not have the world info for this lookup and message to be fully accurate.
1 parent 688ae0a commit f66fd47

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

base/error.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ end
162162
## keyword arg lowering generates calls to this ##
163163
function kwerr(kw, args::Vararg{Any,N}) where {N}
164164
@noinline
165-
throw(MethodError(Core.kwcall, (kw, args...)))
165+
throw(MethodError(Core.kwcall, (kw, args...), tls_world_age()))
166166
end
167167

168168
## system error handling ##

base/errorshow.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,11 @@ function showerror(io::IO, ex::MethodError)
327327
end
328328
end
329329
if ex.world == typemax(UInt) || hasmethod(f, arg_types, world=ex.world)
330+
if !isempty(kwargs)
331+
print(io, "\nThis method does not support all of the given keyword arguments (and may not support any).")
332+
end
330333
if ex.world == typemax(UInt) || isempty(kwargs)
331334
print(io, "\nThis error has been manually thrown, explicitly, so the method may exist but be intentionally marked as unimplemented.")
332-
else
333-
print(io, "\nThis method may not support any keyword arguments.")
334335
end
335336
elseif hasmethod(f, arg_types) && !hasmethod(f, arg_types, world=ex.world)
336337
curworld = get_world_counter()

test/errorshow.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,7 @@ end
671671

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

676676
@test_throws "MethodError: no method matching kwcall()" Core.kwcall()
677677
end

0 commit comments

Comments
 (0)