mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 17:18:04 +00:00
2958754ed8
The data structure in the front end for recording which getter names can be type promoted via "field promotion", `fieldNonPromotabilityInfo`, is a field in the `SourceLibraryBuilder` class. This means that each library tracks its own notion of which getter names are promotable. This makes sense because only private getter names are eligible for field promotion, and private getter names can only be used to access declarations in the same library. Prior to this commit, if the user tried to perform type promotion on a _public_ getter name, the shared flow analysis logic would correctly deem that public name non-promotable and reject the promotion. If the front end then called `FlowAnalysis.whyNotPromoted` (which it typically does to get details about failed type promotions that lead to compile-time errors), flow analysis would then use `FlowAnalysisOperations.whyPropertyIsNotPromotable` to query the `fieldNonPromotabilityInfo` data structure. Since `fieldNonPromotabilityInfo` is tracked separately for each library, if the public getter referred to a field declared in some other library, no information would be found, so `FlowAnalysisOperations.whyPropertyIsNotPromotable` would return `null`. This would lead flow analysis to incorrectly conclude that the reason for the getter name being non-promotable was due to a conflict with some other getter with the same name in the same library, so it would return `PropertyNotPromotedForNonInherentReason` to the front end. The front end would then iterate through `fieldNonPromotabilityInfo` looking for conflicting getters, again finding nothing. This led to an assertion failure, because it doesn't make logical sense for a getter name to be non-promotale due to conflicts if there are no conflicts. In production builds of the front end (with assertions disabled), the behavior was that the compile-time error would simply have no "why not promoted" context message (which is fairly benign, but still undesirable). This commit fixes the bug by modifying the shared logic for `FlowAnalysis.whyNotPromoted` so that if the getter name in question doesn't begin with `_` (meaning it's public), then it doesn't bother calling `FlowAnalysisOperations.whyPropertyIsNotPromotable` at all, because it knows the non-promotion reason is because the name is public. As a result, the correct context message gets generated, and there is no assertion failure. Note that the language test included in this commit doesn't check that the correct context message is generated, because the test infrastructure isn't capable of testing context messages that point to other files. But it does still serve to validate that the assertion no longer fires. Fixes https://github.com/dart-lang/sdk/issues/54777. Change-Id: I697f55acad7c162bc5f49f2824c91d172497f344 Bug: https://github.com/dart-lang/sdk/issues/54777 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349405 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Chloe Stefantsova <cstefantsova@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.