-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch
Description
This works:
julia> f(x::Int; y::Union(Symbol, Int)=:foo) = println(y)
# methods for generic function f
f(x::Int64) at none:1
julia> f(1)
foo
julia> f(1, y=:bar)
bar
julia> f(1, y=3)
3
A parametric version instead fails with a cryptic message:
julia> g{T}(x::T; y::Union(Symbol, T)=:foo) = println(y)
# methods for generic function g
g{T}(x::T) at none:1
julia> g(1)
ERROR: no method g#g2(Symbol,Int64)
julia> g(1, y=:bar)
ERROR: no method g#g2(Symbol,Int64)
julia> g(1, y=3)
3
Possibly related, this should be an error but less cryptic and preferrably when the function is defined rather than used.
julia> h(x::Int; y::Int=0.0) = println(y)
# methods for generic function h
h(x::Int64) at none:1
julia> h(1)
ERROR: no method h#g3(Float64,Int64)
Metadata
Metadata
Assignees
Labels
types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch