[breaking change] Compute closures of type schemas in the upper bound computations in the CFE as specified #56466
Labels
breaking-change-approved
breaking-change-request
This tracks requests for feedback on breaking changes
legacy-area-front-end
Legacy: Use area-dart-model instead.
Intended Change
The implementation of the algorithm for computing the upper bound of type schemas (also known as UP) will be adjusted. It will be aligned with the specification and the implementation of it in the Analyzer: the closures of the type schemas will be computed when the parts of the type schemas are passed into the subtyping algorithm, not at the very beginning of the upper bound computation.
Rationale
There is a discrepancy between the specification of the algorithm for computing the upper bound of type schemas and its implementation in the CFE. Moreover, the Analyzer complies to the specification in that regard, making the implementation in the CFE an outlier. Specifically, the CFE computes closures of the type schemas at the very beginning of computing the upper bound instead of computing closures of the parts of the schemas only when they are passed into the subtyping algorithm.
The discrepancy is a blocker for the upcoming language update implemented at https://dart-review.googlesource.com/c/sdk/+/364721.
Expected Impact
The impact of this change is expected to be very low, since none of the effects of the discrepancy were observed so far and the Analyzer is implementing the algorithm as specified, ensuring the code that passes through both tools assumes the specified behavior of the compiler. A trial run of this change over Google's internal Dart code base caused zero breakages.
However, it's theoretically possible that some code could change behavior as a result of this change. Here is an example of a program whose behavior would change:
Today this program is accepted by the Analyzer, but induces the following compile-time error when compiled by the CFE:
With the change, both tools will accept the program.
Mitigation
In the unlikely event that some code is affected by the change, the old behavior may be restored by supplying explicit types where previously they were inferred. For example, in the program above the discrepancy in UP is visible only because the UP algorithm is used in inference of the type argument in the constructor invocation of
A
.The text was updated successfully, but these errors were encountered: