Skip to content

Commit 8feef52

Browse files
JeffBezansonKristofferC
authored andcommitted
fix hasmethod with kwargs to exclude positional arg names (#58410)
(cherry picked from commit 7df60f4)
1 parent e6371c9 commit 8feef52

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
@@ -1035,11 +1035,11 @@ function hasmethod(f, t, kwnames::Tuple{Vararg{Symbol}}; world::UInt=get_world_c
10351035
match = ccall(:jl_gf_invoke_lookup, Any, (Any, Any, UInt), tt, nothing, world)
10361036
match === nothing && return false
10371037
kws = ccall(:jl_uncompress_argnames, Array{Symbol,1}, (Any,), (match::Method).slot_syms)
1038+
kws = kws[((match::Method).nargs + 1):end] # remove positional arguments
10381039
isempty(kws) && return true # some kwfuncs simply forward everything directly
10391040
for kw in kws
10401041
endswith(String(kw), "...") && return true
10411042
end
1042-
kwnames = collect(kwnames)
10431043
return issubset(kwnames, kws)
10441044
end
10451045

test/reflection.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ f(x::Int; y=3) = x + y
931931
@test hasmethod(f, Tuple{Int})
932932
@test hasmethod(f, Tuple{Int}, ())
933933
@test hasmethod(f, Tuple{Int}, (:y,))
934+
@test !hasmethod(f, Tuple{Int}, (:x,))
934935
@test !hasmethod(f, Tuple{Int}, (:jeff,))
935936
@test !hasmethod(f, Tuple{Int}, (:y,), world=typemin(UInt))
936937
g(; b, c, a) = a + b + c

0 commit comments

Comments
 (0)