(Julia Version 0.3.4-pre+47)
I didn't expect this
julia> f{T}(x::Complex{T},y::T) = println("here")
f (generic function with 1 method)
julia> f{T}(x::Complex{T},y::Real) = begin println("there");
f(x,convert(T,y)) end
f (generic function with 2 methods)
julia> methods(f)
# 2 methods for generic function "f":
f{T}(x::Complex{T},y::Real) at none:1
f{T}(x::Complex{T},y::T) at none:1
julia> f(Complex(1.0),1.0)
The last line causes an infinite recursion because
julia> @which f(Complex(1.0),1.0)
f{T}(x::Complex{T},y::Real) at none:1
I expected f{T}(x::Complex{T},y::T) to be more specific than
f{T}(x::Complex{T},y::Real).
If I remove ::Real, everything works as I expect
julia> f{T}(x::Complex{T},y::T) = println("here")
f (generic function with 1 method)
julia> f{T}(x::Complex{T},y) = begin println("there"); f(x,convert(T,y)) end
f (generic function with 2 methods)
julia> methods(f)
# 2 methods for generic function "f":
f{T}(x::Complex{T},y::T) at none:1
f{T}(x::Complex{T},y) at none:1
julia> f(Complex(1.0),1.0)
here
julia> f(Complex(1.0),1)
there
here
I thought it might have been an instance of
https://github.com/JuliaLang/julia/issues/7221 but defining the methods in
the opposite order doesn't change the result.