We don't allow type variable declarations of the form T extends T, or T extends S, S extends T. The analyzer currently accepts type variable declarations of the form T extends FutureOr<T>, but the CFE crashes on such declarations. With NNBD, we will also have the ability to write T extends T? or T extends S, S extends T? unless we specify otherwise.
Should we consider making these an error?
My inclination is yes. In general, this feels to be pushing up against (or crossing) an important boundary in the equational theory that may bite us if we eventually add union types and attempt to re-interpret ? and FutureOr as union types. Note that for example T extends T | Never is essentially another way of writing T extends T, which suggests the kinds of problems that may arise.
I also haven't found any uses for this kind of equation, and since the CFE doesn't accept the FutureOr example, there is almost certainly no existing code that uses this feature.
One way of specifying this is to say that given a set of type variable declarations of the form X0 extends B0, ..., Xn extends Bn, construct a graph with one node for every Xi, and edges from Xi to Xj iff Xi occurs in a top level union in Bj, and say that it is an error if that graph has any cycles. We say that Xi occurs in a top level union in a type T iff:
T is `Xi
T is S? and Xi occurs in a top level union in S
T is FutureOr<S> and Xi occurs in a top level union in S
@eernstg @lrhn @munificent thoughts?
cc @stereotype441
We don't allow type variable declarations of the form
T extends T, orT extends S, S extends T. The analyzer currently accepts type variable declarations of the formT extends FutureOr<T>, but the CFE crashes on such declarations. With NNBD, we will also have the ability to writeT extends T?orT extends S, S extends T?unless we specify otherwise.Should we consider making these an error?
My inclination is yes. In general, this feels to be pushing up against (or crossing) an important boundary in the equational theory that may bite us if we eventually add union types and attempt to re-interpret
?andFutureOras union types. Note that for exampleT extends T | Neveris essentially another way of writingT extends T, which suggests the kinds of problems that may arise.I also haven't found any uses for this kind of equation, and since the CFE doesn't accept the
FutureOrexample, there is almost certainly no existing code that uses this feature.One way of specifying this is to say that given a set of type variable declarations of the form
X0 extends B0, ..., Xn extends Bn, construct a graph with one node for everyXi, and edges fromXitoXjiffXioccurs in a top level union inBj, and say that it is an error if that graph has any cycles. We say thatXioccurs in a top level union in a typeTiff:Tis `XiTisS?andXioccurs in a top level union inSTisFutureOr<S>andXioccurs in a top level union inS@eernstg @lrhn @munificent thoughts?
cc @stereotype441