Skip to content

Add full kwarg support to signature #6

@oxinabox

Description

@oxinabox

Follow up for once #1 is merged.
Adding keyword support.

It is just really fiddly.

The information is there but its not in a very easy to acess form:

julia> g(; x=1, y=3) = x+y
g (generic function with 2 methods)

julia> g(a; b=2) = a-b
g (generic function with 2 methods)

julia> meths = methods(g)
# 2 methods for generic function "g":
[1] g(; x, y) in Main at REPL[65]:1
[2] g(a; b) in Main at REPL[66]:1

julia> kwsorter_meths = methods(meths.mt.kwsorter)
# 2 methods for anonymous function "g##kw":
[1] (::var"#g##kw")(::Any, ::typeof(g)) in Main at REPL[65]:1
[2] (::var"#g##kw")(::Any, ::typeof(g), a) in Main at REPL[66]:1

julia> Base.uncompressed_ast(first(kwsorter_meths))
CodeInfo(
     @ REPL[65]:1 within `g##kw'
1 ── %1  = Base.haskey(@_2, :x)
└───       goto #3 if not %1
2 ──       @_6 = Base.getindex(@_2, :x)
└───       goto #4
3 ──       @_6 = 1
4 ┄─       x = @_6
│    %7  = Base.haskey(@_2, :y)
└───       goto #6 if not %7
5 ──       @_7 = Base.getindex(@_2, :y)
└───       goto #7
6 ──       @_7 = 3
7 ┄─       y = @_7
│    %13 = (:x, :y)
│    %14 = Core.apply_type(Core.NamedTuple, %13)
│    %15 = Base.structdiff(@_2, %14)
│    %16 = Base.pairs(%15)
│    %17 = Base.isempty(%16)
└───       goto #9 if not %17
8 ──       goto #10
9 ──       Base.kwerr(@_2, @_3)
10 ┄ %21 = Main.:(var"#g#10")(x, y, @_3)
└───       return %21
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    signaturerelating to the signature function to get def from methods

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions