Skip to content

Vararg argument as optional argument gives error when there is a keyword argument. #40964

@frankwswang

Description

@frankwswang

MWE:

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],)

System info:

julia> versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-1065G7 CPU @ 1.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, icelake-client)
Environment:
  JULIA_NUM_THREADS = 6

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. Initial Discourse link is here.

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorcompiler:loweringSyntax lowering (compiler front end, 2nd stage)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions