Apparently more-specialised method not called

I don’t understand the following behaviour:

julia> f(x::Real, y::Real) = x+y
f (generic function with 1 method)

julia> f(x::T, y::T) where T = x - y   # 0.6 syntax;   on 0.5 would be  f{T}(x::T, y::T) = x - y
f (generic function with 2 methods)

julia> f(3, 4)
7

Shouldn’t the second, more specialized (to my eyes) method be called instead?

This is a missing ambiguity similar to (and simpler than) the case I had in https://github.com/JuliaLang/julia/issues/20056#issuecomment-272757460

1 Like

The unambiguous case works correctly.

julia> f(::Real, ::Real) = 1
f (generic function with 1 method)

julia> f(::T, ::T) where T <: Real = 2
f (generic function with 2 methods)

julia> f(3, 4)
2