Open
Description
During my development of https://dart-review.googlesource.com/c/sdk/+/400660, I ran into a bug where ElementLocationImpl.fromElement
is not always correct in assuming that LocalFunctionElementImpl.wrappedElement._enclosingElement3
is always of type ExecutableElementImpl
:
ElementLocationImpl.fromElement(Element2 element) {
List<String> components = <String>[];
Element2? ancestor = element;
while (ancestor != null) {
if (ancestor is! ElementImpl2) {
...
} else {
components.insert(0, ancestor.identifier);
if (ancestor is LocalFunctionElementImpl) {
ancestor = (ancestor.wrappedElement._enclosingElement3
as ExecutableElementImpl)
.element;
} else {
ancestor = ancestor.enclosingElement2;
}
}
}
_components = components.toFixedList();
}
To repro this failure, check out patchset 4 of https://dart-review.googlesource.com/c/sdk/+/400660 and change line 4435 of pkg/_fe_analyzer_shared/lib/src/flow_analysis/flow_analysis.dart
from this:
new Set.identity();
to this:
{};
Then run the test suite pkg/analyzer/test/generated/invalid_code_test.dart
.