Function with Vararg and Missing ambiguity check?

Consider the function with two methods

julia> f(::Integer, x::Vararg{Integer, N}) where {N} = NTuple{N,Int}(s) # Here s intentional
f (generic function with 1 method)

julia> f(::Integer, x::Vararg{Any, N}) where {N} = NTuple{N,Int}(x)
f (generic function with 2 methods)

For the one argument case they seem ambiguous but the signature with Vararg{Integer, N} is used. Is there

julia> f(9)
ERROR: UndefVarError: s not defined
Stacktrace:
 [1] f(::Int64)
   @ Main ./REPL[1]:1
 [2] top-level scope
   @ REPL[3]:1

It only become ambiguous if I have one more method that is more specific than Any for Vararg. Is this intentional since Integer is more specific or left as an edge case?

I think since we have:

julia> Tuple{Integer,Vararg{Integer}} <: Tuple{Integer,Vararg{Any}}
true

if the first one matches, it is always considered more specific.

1 Like