Skip to content

Normalise upper bound of T in Foo{T} where T to Foo's upper bound #37901

@jakobnissen

Description

@jakobnissen

@andreasnoack mentioned this on Slack:

julia> (Complex{T} where T) <: Complex
false

The annoying part is that in Complex, the upper bound for the TypVar is Real, but in Complex{T} where T, the upper bound is simply Any. But since it's not possible to instantiate e.g. Complex{String}:

julia> Complex{String}
ERROR: TypeError: in Complex, in T, expected T<:Real, got Type{String}
Stacktrace:
 [1] top-level scope at REPL[17]:1

Then the extent of the two types Complex{T} where {T <: Any} is the same as Complex{T} where {T <: Real}. So Julia might as well normalise it to Complex{T} where {T <: Real}. Similarly for e.g. Complex{<:Number}.

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