Problems with null check in NonParameterVariableElementImpl.enclosingElement3 #59750
Labels
analyzer-api
Issues that impact the public API of the analyzer package
area-analyzer
Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
P2
A bug or feature request we're likely to work on
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
During my development of https://dart-review.googlesource.com/c/sdk/+/400660, I ran into a subtle bug where the following null check (in the class
NonParameterVariableElementImpl
) was failing:After discussion with @bwilkerson, I suspect this null check doesn't belong here. Variable elements can have a
null
enclosing element, if the variable is in a local function, as you can see from the declaration of_NonTopLevelVariableOrParameter.enclosingElement2
:This leads to some fragility, since local functions are fairly rare. I wonder if perhaps we should standardize on saying that either that (a) all local variables have a null
enclosingElement2
, or (b) all local variables have a non-nullenclosingElement2
.To repro the failure, check out patchset 3 of https://dart-review.googlesource.com/c/sdk/+/400660 and change lines 1973-1974 of
pkg/analyzer/lib/src/dart/resolver/resolution_visitor.dart
from this:to this:
..enclosingElement3 = first.enclosingElement2.asElement
Then run the test suite
pkg/analyzer/test/src/dart/resolution/switch_expression_test.dart
.The text was updated successfully, but these errors were encountered: