-
Notifications
You must be signed in to change notification settings - Fork 228
Description
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:
Tis `XiTisS?andXioccurs in a top level union inSTisFutureOr<S>andXioccurs in a top level union inS
@eernstg @lrhn @munificent thoughts?