Skip to content

Commit bb6dc83

Browse files
JeffBezansonKristoffer Carlsson
authored andcommitted
fix hasmethod with kwargs to exclude positional arg names (#58410)
(cherry picked from commit 7df60f4)
1 parent fcb5a66 commit bb6dc83

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

base/reflection.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2363,11 +2363,11 @@ function hasmethod(f, t, kwnames::Tuple{Vararg{Symbol}}; world::UInt=get_world_c
23632363
match = ccall(:jl_gf_invoke_lookup, Any, (Any, Any, UInt), tt, nothing, world)
23642364
match === nothing && return false
23652365
kws = ccall(:jl_uncompress_argnames, Array{Symbol,1}, (Any,), (match::Method).slot_syms)
2366+
kws = kws[((match::Method).nargs + 1):end] # remove positional arguments
23662367
isempty(kws) && return true # some kwfuncs simply forward everything directly
23672368
for kw in kws
23682369
endswith(String(kw), "...") && return true
23692370
end
2370-
kwnames = collect(kwnames)
23712371
return issubset(kwnames, kws)
23722372
end
23732373

test/reflection.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ f(x::Int; y=3) = x + y
836836
@test hasmethod(f, Tuple{Int})
837837
@test hasmethod(f, Tuple{Int}, ())
838838
@test hasmethod(f, Tuple{Int}, (:y,))
839+
@test !hasmethod(f, Tuple{Int}, (:x,))
839840
@test !hasmethod(f, Tuple{Int}, (:jeff,))
840841
@test !hasmethod(f, Tuple{Int}, (:y,), world=typemin(UInt))
841842
g(; b, c, a) = a + b + c

0 commit comments

Comments
 (0)