Skip to content

Method with empty arg list not overwritten by definition of keyword-only method (with no defaults) #38066

@klaff

Description

@klaff

See https://discourse.julialang.org/t/im-confused-about-methods/48508/4

In the following snippet, when f()=1 is defined, it should overwrite the previous f(;a)=2 (because dispatch should only be performed on the positional arguments and both of these have no positional arguments). The methods function incorrectly indicates the wrong method survived, and both methods appear to be reachable. Per the discourse discussion, there is some debate on these points!

C:\Users\klaff>julia -q
julia> f(;a)=2
f (generic function with 1 method)

julia> f()=1
f (generic function with 1 method)

julia> methods(f)
# 1 method for generic function "f":
[1] f(; a) in Main at REPL[2]:1

julia> f()
1

julia> f(a=1)
2

julia>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions