Multiple dispatch unexpected function call

If I understand correctly, what happens is:

  • Concrete is the same as Concrete{T} where {T <: AbstractType}, following the definition of Concrete, where the upper bound of the typevar is AbstractType
  • Concrete{T} where T is the same as Concrete{<: Any}, by definition.
  • Hence, the signature is_same(c1::Concrete, c2::Concrete) is more specific than is_same(c1::Concrete{T}, c2::Concrete{T}) where T, and the call dispatches to that.

This can be confirmed by looking at the method table of is_same, where the methods are displayed from more to less specific:

julia> methods(is_same)
# 2 methods for generic function "is_same":
[1] is_same(c1::Concrete, c2::Concrete) in Main at REPL[4]:1
[2] is_same(c1::Concrete{T}, c2::Concrete{T}) where T in Main at REPL[5]:1

Relevant issues:

14 Likes