Skip to content

Method sorting bug #12580

@timholy

Description

@timholy

With these types:

abstract Paint{T, N}

# AbstractColor means just color, no transparency
abstract AbstractColor{T, N} <: Paint{T, N}
abstract Color{T}            <: AbstractColor{T, 3}
abstract AbstractRGB{T}      <: Color{T}
abstract AbstractGray{T}     <: AbstractColor{T, 1}

immutable RGB{T} <: AbstractRGB{T}
    r::T # Red [0,1]
    g::T # Green [0,1]
    b::T # Blue [0,1]
end

# Types with transparency
abstract Transparent{C<:AbstractColor,T,N} <: Paint{T,N}
abstract AbstractColorAlpha{C,T,N} <: Transparent{C,T,N}
immutable ColorAlpha{C<:Color,T} <: AbstractColorAlpha{C,T,4}
    c::C
    alpha::T
end

typealias RGBA{T} ColorAlpha{RGB{T},T}

and these methods:

colortype{C<:AbstractColor    }(::Type{C})                  = C
colortype{C<:AbstractColor    }(::Type{Transparent{C}})     = C
colortype{C<:AbstractColor,T  }(::Type{Transparent{C,T}})   = C
colortype{C<:AbstractColor,T,N}(::Type{Transparent{C,T,N}}) = C
colortype{P<:Transparent}(::Type{P}) = colortype(super(P))

then colortype(RGBA{Float32}) == RGB{Float32} as desired. But in this order:

colortype{C<:AbstractColor    }(::Type{C})                  = C
colortype{P<:Transparent}(::Type{P}) = colortype(super(P))
colortype{C<:AbstractColor    }(::Type{Transparent{C}})     = C
colortype{C<:AbstractColor,T  }(::Type{Transparent{C,T}})   = C
colortype{C<:AbstractColor,T,N}(::Type{Transparent{C,T,N}}) = C

it yields:

ERROR: MethodError: `colortype` has no method matching colortype(::Type{Paint{Float32,4}})
 in colortype at none:1
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    types and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions