-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch
Description
Using a sample code:
abstract Abs
type Foo <: Abs
end
type Bar
val::Int64
end
type Baz
val::Int64
end
import Base.convert
bar{T <: Abs}(x::T) = 2
bar(x) = 1
baz(x) = 1
baz{T <: Abs}(x::T) = 2
convert{T <: Abs}(::Type{Bar}, x::T) = Bar(2)
convert(::Type{Bar}, x) = Bar(1)
convert(::Type{Baz}, x) = Baz(1)
convert{T <: Abs}(::Type{Baz}, x::T) = Baz(2)
@show convert(Bar, Foo())
@show convert(Baz, Foo())
@show bar(Foo())
@show baz(Foo())
I get this on julia 0.3.11:
convert(Bar,Foo()) => Bar(2)
convert(Baz,Foo()) => Baz(2)
bar(Foo()) => 2
baz(Foo()) => 2
and this on latest 0.4:
convert(Bar,Foo()) = Bar(1)
convert(Baz,Foo()) = Baz(2)
bar(Foo()) = 2
baz(Foo()) = 2
Is this supposed to happen? Note that the only difference between Bar and Baz is in the method definition order and it only happens with convert
Metadata
Metadata
Assignees
Labels
types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch