Open yuyichao opened 9 years ago
That was quite a debate. I hope we can agree that 1 <: Any
throwing an error makes sense, and Foo{1} <: Foo{<:Any}
evaluating to true is nonsense—an artifact of an implementation detail instead of a design objective.
I'd like to throw out some possibilities to test the ergonomics of what could be:
Foo{T} where T # T can be any type or any isbits value
Foo{:} # synonym for `Foo{T} where T`
Foo{T} where T<:Any # T must be a type
Foo{<:Any} # synonym for `Foo{T} where T<:Any`
degenerate cases:
T where T # synonym for `Any`
T where T<:Any # synonym for `Any`
Tuple{1} <: Tuple{Any} # throw TypeError? or return false?
Introducing type assertion ::
allows for this:
Foo{n} where n::Int # n must be a value of type `Int`
Foo{::Int} # synonym for `Foo{n} where n::Int`
but also allows these redundancies:
Foo{::Type} # synonym for `Foo{<:Any}`
Foo{::Type{Int}} # synonym for `Foo{Int}`
Foo{::Type{<:Number}} # synonym for `Foo{<:Number}`
It's attractive, but I'm not sure how to feel since <:
returns a Boolean while ::
does not; I could also argue for isa
here.
Why was this closed?
Will this issue be reconsidered/reopened anytime soon in the future?
When a type parameter is specified to be
T <: Top
, it actually accept non-type as parameters as well.Although
1
and1.2
are clearly not subtypes ofTop
This is also the case for the builtin
Type
(some other types likeArray
doesn't even have this constraint specified)No error is raised even if this parameter is used as a type of a field
The same thing happens for
T <: Any
although this time it correctly rejectCore.Unref
Specifying other types seems fine
Another related issue is that
Vararg
doesn't specify any constraint on the parameter and therefore the following syntax is allowed.