# \`Vararg\` argument as optional argument gives error when there is a keyword argument

**URL:** <https://discourse.julialang.org/t/vararg-argument-as-optional-argument-gives-error-when-there-is-a-keyword-argument/61812>\
**Category:** General Usage\
**Tags:** function\
**Created:** [May 25, 2021, 8:34pm UTC](https://discourse.julialang.org/t/vararg-argument-as-optional-argument-gives-error-when-there-is-a-keyword-argument/61812 "2021-05-25T20:34:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![frankwswang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankwswang/32/18561_2.png) [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Post date:** [May 25, 2021, 8:34pm UTC](https://discourse.julialang.org/t/vararg-argument-as-optional-argument-gives-error-when-there-is-a-keyword-argument/61812/1 "2021-05-25T20:34:38Z")

</div>

MWE:

```julia
julia> foo(a, b::Array{Int, 1}...=[0,0];c="") = @show b
foo (generic function with 3 methods)

julia> goo(a,b::Array{Array{Int, 1}, 1}) = begin
       c = "c"
       foo(a, b...;c)
       end
goo (generic function with 3 methods)

julia> goo(1, [[1,2,3]])
ERROR: TypeError: in typeassert, expected Vector{Int64}, got a value of type Tuple{Vector{Int64}}

julia> foo2(a, b::Array{Int, 1}...;c="") = @show b
foo2 (generic function with 1 method)

julia> goo2(a,b::Array{Array{Int, 1}, 1}) = begin
       c = "c"
       foo2(a, b...;c)
       end
goo2 (generic function with 1 method)

julia> goo2(1, [[1,2,3]])
b = ([1, 2, 3],)
([1, 2, 3],)

julia> foo3(a, b::Array{Int, 1}...=[0,0]) = @show b
foo3 (generic function with 2 methods)

julia> goo3(a,b::Array{Array{Int, 1}, 1}) = foo3(a, b...)
goo3 (generic function with 1 method)

julia> goo3(1, [[1,2,3]])
b = ([1, 2, 3],)
([1, 2, 3],)

```

Based on the differences among `foo`, `foo2`, and `foo3`, I suspect it might have something to do with the keyword argument syntax but I’m not sure.

I don’t know if this is technically a bug since I haven’t seen the usage of `Vararg` arguments as optional arguments on the official documentation (I might have missed it so feel free to point out); on the other hand since it’s not forbidden and yet we have this kind of errors. So I think it’s worth pointing out. Maybe fix the issue or warn people by throwing an error when they try to construct such a function? Thank you!

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [May 26, 2021, 10:59am UTC](https://discourse.julialang.org/t/vararg-argument-as-optional-argument-gives-error-when-there-is-a-keyword-argument/61812/2 "2021-05-26T10:59:35Z")

</div>

I think it’s a bug:

```julia
# works:
julia> foo(a,b::Array{Int, 1}... ;c="") = @show b
foo (generic function with 1 method)

julia> foo(1,[1,2] ; c="")
b = ([1, 2],)
([1, 2],)

julia> foo(1)
b = ()
()

# works:
julia> goo(a,b::Array{Int, 1}...=[0,0] ) = @show b
goo (generic function with 2 methods)

julia> goo(1)
b = ([0, 0],)
([0, 0],)

julia> goo(1,[1,2])
b = ([1, 2],)
([1, 2],)

# doesn't work:
julia> hoo(a,b::Array{Int, 1}...=[0,0] ;c="") = @show b
hoo (generic function with 2 methods)

```

I think it could work, so my guess it’s a bug. Do you mind opening an issue? [Issues · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues)

---

<div class="post-metadata">

**Author:** ![frankwswang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frankwswang/32/18561_2.png) [@frankwswang](https://discourse.julialang.org/u/frankwswang)\
**Post date:** [May 26, 2021, 11:00pm UTC](https://discourse.julialang.org/t/vararg-argument-as-optional-argument-gives-error-when-there-is-a-keyword-argument/61812/3 "2021-05-26T23:00:02Z")

</div>

Sure no problem. 👌 I just wanted to make sure if I missed something.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [May 27, 2021, 6:05am UTC](https://discourse.julialang.org/t/vararg-argument-as-optional-argument-gives-error-when-there-is-a-keyword-argument/61812/4 "2021-05-27T06:05:30Z")

</div>

[https://github.com/JuliaLang/julia/issues/40964](https://github.com/JuliaLang/julia/issues/40964)
