# Keyword argument and type parameter error - triangular dispatch

**URL:** <https://discourse.julialang.org/t/keyword-argument-and-type-parameter-error-triangular-dispatch/8870>\
**Category:** General Usage\
**Tags:** bug\
**Created:** [February 6, 2018, 7:21pm UTC](https://discourse.julialang.org/t/keyword-argument-and-type-parameter-error-triangular-dispatch/8870 "2018-02-06T19:21:48Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [February 6, 2018, 7:21pm UTC](https://discourse.julialang.org/t/keyword-argument-and-type-parameter-error-triangular-dispatch/8870/1 "2018-02-06T19:21:48Z")

</div>

The following errors:

```julia
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
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)

```

---

<div class="post-metadata">

**Author:** ![saschatimme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/saschatimme/32/10313_2.png) [@saschatimme](https://discourse.julialang.org/u/saschatimme)\
**Post date:** [February 6, 2018, 7:27pm UTC](https://discourse.julialang.org/t/keyword-argument-and-type-parameter-error-triangular-dispatch/8870/2 "2018-02-06T19:27:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Post date:** [February 6, 2018, 7:34pm UTC](https://discourse.julialang.org/t/keyword-argument-and-type-parameter-error-triangular-dispatch/8870/3 "2018-02-06T19:34:13Z")

</div>

> [@saschatimme](#):
>
> You cannot dispatch on keyword arguments,

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
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
julia> f(;a::T=1) where {T} = a
f (generic function with 1 method)

```

But this doesn’t:

```julia
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)

```
