You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
The following seems very confusing and is possibly a bug, or could at least be handled better.
This example works as expected
However, if we change the first line to
The following definition is now needed to catch the
Bar()
The problem boils down to that in the second case we have
the following are equivalent and false
But that the following is true
So
Bar
meansBar{T} where T
even thoughT
has to be restricted toNumber
byFoo
and the following is illegal:Bar{T where T}
.Shouldn't the type restrictions propagate from the supertypes, so that
Bar
is equivalent toBar{T} where T<:Number
?The text was updated successfully, but these errors were encountered: