In ScopeResolverVisitor, don't visit identifiers to the right of `.`.
There's no need to visit these identifiers because they aren't looked
up using the current scope. Previously, we avoided doing these
lookups by doing some `is` and `identical` checks in
visitSimpleIdentifier, but it's more efficient (and more
straightforward) to simply avoid visiting the identifiers altogether.
Change-Id: Ibea28e196b206d88f5ad765d3d64a24c7b0e7d5e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209855
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index 381d5fc..d776e90 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -2913,6 +2913,20 @@
}
@override
+ void visitMethodInvocation(MethodInvocation node) {
+ // Only visit the method name if there's no real target (so this is an
+ // unprefixed function invocation, outside a cascade). This is the only
+ // circumstance in which the method name is meant to be looked up in the
+ // current scope.
+ node.target?.accept(this);
+ if (node.realTarget == null) {
+ node.methodName.accept(this);
+ }
+ node.typeArguments?.accept(this);
+ node.argumentList.accept(this);
+ }
+
+ @override
void visitMixinDeclaration(MixinDeclaration node) {
Scope outerScope = nameScope;
try {
@@ -2943,6 +2957,20 @@
}
@override
+ void visitPrefixedIdentifier(PrefixedIdentifier node) {
+ // Do not visit the identifier after the `.`, since it is not meant to be
+ // looked up in the current scope.
+ node.prefix.accept(this);
+ }
+
+ @override
+ void visitPropertyAccess(PropertyAccess node) {
+ // Do not visit the property name, since it is not meant to be looked up in
+ // the current scope.
+ node.target?.accept(this);
+ }
+
+ @override
void visitSimpleIdentifier(covariant SimpleIdentifierImpl node) {
// Ignore if already resolved - declaration or type.
if (node.inDeclarationContext()) {
@@ -2950,17 +2978,6 @@
}
// Ignore if qualified.
var parent = node.parent;
- if (parent is PrefixedIdentifier && identical(parent.identifier, node)) {
- return;
- }
- if (parent is PropertyAccess && identical(parent.propertyName, node)) {
- return;
- }
- if (parent is MethodInvocation &&
- identical(parent.methodName, node) &&
- parent.realTarget != null) {
- return;
- }
var scopeLookupResult = nameScope.lookup(node.name);
node.scopeLookupResult = scopeLookupResult;
// Ignore if it cannot be a reference to a local variable.