I feel like I should win a prize if I’ve found a bug this simple!
Anyway, simplifying further:
Scenario 1:
C:\Users\klaff>julia -q
julia> f()=1
f (generic function with 1 method)
julia> f(;a)=2
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()
ERROR: UndefKeywordError: keyword argument a not assigned
Stacktrace:
[1] f() at .\REPL[2]:1
[2] top-level scope at REPL[4]:1
julia> f(a=1)
2
julia>
Scenario 2:
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>
I’m happy to make an issue although I’m not sure exactly what it is. I don’t think order of definition should affect whether a method gets overwritten (but it should affect which is left standing). Certainly in scenario 2 the return from methods(f) is non consistent with reality (both methods are reachable).
How do I know (from a doc standpoint) whether those two methods should be allowed to coexist?
EDIT: If you change the above to f(;a=1)=2, then there are no surprises Whichever is defined last is the one method you get.