mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:21:07 +00:00
b279238e48
In the following expression types, the static type is computed using the least upper bound ("LUB") of their subexpressions (adjusted as appropriate to account for the null-shorting behaviors of `??` and `??=`): - Conditional expressions (`a ? b : c`) - If-null expressions (`a ?? b`) - If-null assignments (`a ??= b`) - Switch expressions (`switch (s) { p0 => e0, ... }`) This can lead to problems since the LUB computation sometimes produces a greater bound than is strictly necessary (for example if there are multiple candidate bounds at the same level of the class hierarchy, the LUB algorithm will walk up the class hierarchy until it finds a level at which there is a unique result). For a discussion of the kind of problems that can arise, see https://github.com/dart-lang/language/issues/1618. This change improves the situation by changing the analysis of these four expression types so that after computing a candidate static type using LUB, if that static type does not satisfy the expression's context, but the static types of all the subexpressions *do* satisfy the expression's context, then the greatest closure of the context is used as the static type instead of the LUB. This is the algorithm proposed in https://github.com/dart-lang/language/issues/1618#issuecomment-1507241494. This is theoretically a breaking change (since it can change code that demotes a local variable into code that doesn't, and then the demotion or lack of demotion can have follow-on effects in later code). So it is implemented behind the `inference-update-3` experiment flag. However, in practice it is minimally breaking; a test over all of google3 found no test failures from turning the feature on. Since one of these expression types (switch expressions) is implemented in `package:_fe_analyzer_shared`, but the other three are implemented separately in the `package:analyzer` and `package:front_end`, this change required modifications to all three packages. I've included tests for the new functionality, following the testing style of each package. I've also included a comprehensive set of language tests that fully exercises the feature regardless of how it's implemented. Since `package:front_end` has many different implementations of `??=` depending on the form of the left hand side, I've tried to be quite comprehensive in the language tests, covering each type of assignable expression that might appear to the left of `??=`. Change-Id: I13a6168b6edf6eac1e52ecdb3532985af19dbcdf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353440 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@google.com> Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Erik Ernst <eernst@google.com> |
||
---|---|---|
.. | ||
co19 | ||
corelib | ||
dartdevc | ||
ffi | ||
language | ||
lib | ||
modular | ||
standalone | ||
web | ||
legacy_status_dart2js.csv | ||
OWNERS | ||
README.md |
This directory contains tests of the language and core library implementations. For more information, see https://github.com/dart-lang/sdk/wiki/Testing.