julia> immutable Test1{T<:AbstractFloat} <: Number
x::T
y::T
end
julia> import Base.convert; convert{T}(::Type{Tuple{T,T}}, x::Test1{T}) = (x.x, x.y)
julia> Tuple{Float64,Float64}(Test1(.2,2.2))
ERROR: MethodError: Cannot `convert` an object of type Test1{Float64} to an object of type Float64
This may have arisen from a call to the constructor Float64(...),
since type constructors fall back to convert methods.
Stacktrace:
[1] _totuple at .\tuple.jl:211 [inlined]
[2] Tuple{Float64,Float64}(::Test1{Float64}) at .\tuple.jl:198
You’re defining a conversion but calling the constructor. Calling convert directly works, or you can define a custom constructor. Or even better, define iteration for your Test1 object and the default constructor will just work.