Method ambiguity involving diagonal types

frankwswang
Sat, 15 Nov 2025 22:33:32 +0000
General Usage

MWE:

julia> f1(argL::T, argR::T) where {T} = 1
f1 (generic function with 1 method)

julia> f1(argL::T1, argR::T2) where {T, T1<:AbstractArray{T}, T2<:AbstractArray{T}} = 2
f1 (generic function with 2 methods)

julia> f1([1], [1])
2

Shouldn’t f1([1], [1]) throw a MethodError since neither method is more specific than the other (i.e., the set of argument types of one method is a proper subset of another) when the input argument types are (::T, ::T) where T==Vector{Int}?

I would imagine that one needs to implement the following method to avoid the ambiguity:

f1(argL::T, argR::T) where {T<:AbstractArray} = 3

11 posts - 5 participants