Keyword argument and type parameter error - triangular dispatch

bug

#1

The following errors:

julia> f(a::Tx; b::T=0.1) where {T, Tx<:AbstractVector{T}} = a .* b
ERROR: UndefVarError: T not defined

but it makes sense not to. What do you think?
These expectedly go through:

julia> f(a::Tx, b::T=0.1) where {T, Tx<:AbstractVector{T}} = a .* b
f (generic function with 2 methods)

julia> f(a::Tx) where {T, Tx<:AbstractVector{T}} = a
f (generic function with 2 methods)

#2

You cannot dispatch on keyword arguments, therefore you get the error. But the error message could definitely be better…


#3

I see, but am I? I think T and Tx can both be inferred from the positional arguments, then ::T in the keyword arguments is essentially an assertion. But I think the problem is that types asserted for kwargs should be explicitly stated in the positional arguments, that is triangular typing isn’t supported. The following for instance work:

julia> f(a::AbstractVector{T}; b::T=0.1) where {T} = a .* b
f (generic function with 3 methods)

julia> f(a::Tx; b=T(0.1)) where {T, Tx<:AbstractVector{T}} = a .* b
f (generic function with 3 methods)

This also goes through!

julia> f(;a::T=1) where {T} = a
f (generic function with 1 method)

But this doesn’t:

julia> f(;a::Tx=[1]) where {T,Tx<:AbstractVector{T}} = a
WARNING: static parameter T does not occur in signature for f at REPL[4]:1.
The method will not be callable.
f (generic function with 1 method)