Skip to content

Unions with static type parameters are problematic #3738

@GunnarFarneback

Description

@GunnarFarneback

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

No one assigned

    Labels

    types 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