Vararg (sub)type parameter undocumented dispatch weirdness

The easiest way to test dispatch behavior is with subtyping relations. Julia’s dispatch rule is very simple and consistent in this respect: the method selected has the most specific type signature that your argument is a subtype of. For example:

julia> x = zero(UInt8), zero(Int8)
(0x00, 0)

julia> typeof(x) <: Tuple{Vararg{<:Integer}}  # a4's method signature
true

julia> typeof(x) <: Tuple{Vararg{T}} where T<:Integer # a5's method signature
false

The developer documentation is a good reference for Julia’s subtyping rules. For a deeper dive, this paper is a classic.

1 Like