Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excluding parametric restrictions allow for defining subtypes which are not truely subtypes #36225

Closed
omus opened this issue Jun 10, 2020 · 2 comments
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@omus
Copy link
Member

omus commented Jun 10, 2020

When applying a restriction to a abstract type parameter a subtype it is possible to define a subtype that is not actually a subtype:

julia> abstract type AbstractFoo{T<:Integer} end

julia> struct Foo1{T} <: AbstractFoo{T} end

julia> struct Foo2{T <: Integer} <: AbstractFoo{T} end

julia> Foo1 <: AbstractFoo
false

julia> Foo2 <: AbstractFoo
true

I believe this to be a bug as by definition Foo1 is a subtype of AbstractFoo. Similarly definitions where the subtype attempts to expand the scope of the parameter should probably be disallowed:

struct Foo3{T <: Real} <: AbstractFoo{T} end
@omus omus added the types and dispatch Types, subtyping and method dispatch label Jun 10, 2020
@vtjnash
Copy link
Member

vtjnash commented Jun 10, 2020

You aren't making a broken subtype, just defining a primary alias that isn't a subtype of the other primary alias:

julia> abstract type AbstractFoo{T<:Integer} end

julia> struct Foo2{T <: Integer} <: AbstractFoo{T} end

julia> (Foo2{T} where T) <: AbstractFoo
false

julia> (Foo2{T} where T) <: (AbstractFoo{T} where T)
true

@JeffBezanson
Copy link
Member

Duplicate of #9441

@JeffBezanson JeffBezanson marked this as a duplicate of #9441 Jun 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

No branches or pull requests

3 participants