Skip to content

dispatch behavior of optional arguments #7357

Description

@nalimilan

Since empty arrays [] are of type Vector{None}, it will sometimes happen that people do mistakes like this:

julia> function f1(x::Vector{Int} = [])
           true
       end
f1 (generic function with 3 methods)

julia> function f2(; x::Vector{Int} = [])
           true
       end
f2 (generic function with 1 method)

julia> f1()
ERROR: no method f1(Array{None,1})
 in f1 at none:2

julia> f2()
ERROR: no method __f2#3__(Array{None,1})

At least, in the second case, the function name is a bit weird. In the first case, the line number doesn't correspond to anything interesting. If it's possible, it would be great to print a more explicit message, like "default argument value is of an incorrect type".

Metadata

Metadata

Assignees

Labels

breakingThis change will break codeneeds decisionA decision on this change is neededspeculativeWhether the change will be implemented is speculativetypes and dispatchTypes, subtyping and method dispatch

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions