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

Subtyping type parameters in abstract types not propagating #43971

Closed
mfalt opened this issue Jan 28, 2022 · 2 comments
Closed

Subtyping type parameters in abstract types not propagating #43971

mfalt opened this issue Jan 28, 2022 · 2 comments
Labels
types and dispatch Types, subtyping and method dispatch

Comments

@mfalt
Copy link
Contributor

mfalt commented Jan 28, 2022

The following seems very confusing and is possibly a bug, or could at least be handled better.
This example works as expected

abstract type Foo{S} end
struct Bar{T} <: Foo{T} end
(::Type{T})()  where T <: Foo = println(T)

Bar{Float64}() # Prints "Bar{Float64}"
Bar() # Prints "Bar"

However, if we change the first line to

abstract type Foo{S<:Number} end
struct Bar{T} <: Foo{T} end
(::Type{T})()  where T <: Foo = println(T)

Bar{Float64}() # Prints: "Bar{Float64}"
Bar() # Does not work

The following definition is now needed to catch the Bar()

(::Type{T})() where {T<:Foo{S} where S} = println(T)
Bar() # Prints "Bar"

The problem boils down to that in the second case we have
the following are equivalent and false

Bar  <: Foo # False
Bar <: Foo{S} where S<:Number # False

But that the following is true

Bar{T where T <: Number} <: Foo # True
(Bar{T} where T<:Number) <: Foo # True

So Bar means Bar{T} where T even though T has to be restricted to Number by Foo and the following is illegal: Bar{T where T}.
Shouldn't the type restrictions propagate from the supertypes, so that
Bar is equivalent to Bar{T} where T<:Number?

@JeffBezanson JeffBezanson added the types and dispatch Types, subtyping and method dispatch label Jan 28, 2022
@JeffBezanson
Copy link
Member

You're right; this is a long-standing issue. Duplicate of #6383

@mfalt
Copy link
Contributor Author

mfalt commented Jan 28, 2022

Thanks! I suspected it was known, but couldn't find the issue.

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

2 participants