Skip to content

fix kw handling and filter out a new internal symbol from arguments #137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ function keywords(func, m::Method)
# table is a MethodTable object. For some reason, the :kwsorter field is not always
# defined. An undefined kwsorter seems to imply that there are no methods in the
# MethodTable with keyword arguments.
if isdefined(table, :kwsorter)
if !(Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0) || isdefined(table, :kwsorter)
# Fetching method keywords stolen from base/replutil.jl:572-576 (commit 3b45cdc9aab0):
kwargs = VERSION < v"1.4.0-DEV.215" ? Base.kwarg_decl(m, typeof(table.kwsorter)) : Base.kwarg_decl(m)
if isa(kwargs, Vector) && length(kwargs) > 0
Expand Down Expand Up @@ -463,7 +463,7 @@ function arguments(m::Method)
local args = map(argnames[1:nargs(m)]) do arg
arg === Symbol("#unused#") ? "_" : arg
end
return filter(arg -> arg !== Symbol("#self#"), args)
return filter(arg -> arg !== Symbol("#self#") && arg !== Symbol("#ctor-self#"), args)
end
return Symbol[]
end
Expand Down
4 changes: 3 additions & 1 deletion test/tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ end
@test isdefined(methods(M.j_1), :mt)
local mt = methods(M.j_1).mt
@test isa(mt, Core.MethodTable)
@test isdefined(mt, :kwsorter)
if Base.fieldindex(Core.MethodTable, :kwsorter, false) > 0
@test isdefined(mt, :kwsorter)
end
# .kwsorter is not always defined -- namely, it seems when none of the methods
# have keyword arguments:
@test isdefined(methods(M.f).mt, :kwsorter) === false
Expand Down