Unexpected ambigiuity in subtype constructor

In A(i), A is an exact type (you could write the signature as (::Type{T})(p::Param) where A<:T<:A), but the argument is <:Any. The opposite is true for (::Type{T})(p::Param) where T<:AbstractT.
You could re-write the problem as

julia> f(::Type{T}, p::Param) where T<:AbstractT = 1
f (generic function with 1 method)

julia> f(::Type{A}, p) = 2
f (generic function with 2 methods)

julia> f(A, Param(2))
ERROR: MethodError: f(::Type{A}, ::Param) is ambiguous. Candidates:
  f(::Type{T}, p::Param) where T<:AbstractT in Main at REPL[73]:1
  f(::Type{A}, p) in Main at REPL[74]:1

which hopefully makes the ambiguity more obvious.

1 Like