Skip to content

Commit 2f5deac

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] avoid doing redundant work when rewriting a prefixed identifier.
When the `ResolverVisitor` rewrites an expression from a prefixed identifier to a property access (which it only does for record types), it's not necessary to re-resolve the target of the property access, because it was already resolved before deciding to rewrite the expression. This change helps pave the way for a follow-up CL in which I'll be adding assertions that fire if the `ResolverVisitor` tries to resolve a given subexpression multiple times. (Doing so is dangerous because it can interfere with the correctness of flow analysis.) Change-Id: I429e0b744683e662772474967188bb1457168795 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399886 Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Paul Berry <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 7e09901 commit 2f5deac

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3412,7 +3412,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
34123412
var rewrittenPropertyAccess =
34133413
_prefixedIdentifierResolver.resolve(node, contextType: contextType);
34143414
if (rewrittenPropertyAccess != null) {
3415-
_resolvePropertyAccess(rewrittenPropertyAccess, contextType);
3415+
_resolvePropertyAccessRhs(rewrittenPropertyAccess, contextType);
34163416
// We did record that `node` was replaced with `rewrittenPropertyAccess`.
34173417
// But if `rewrittenPropertyAccess` was itself rewritten, replace the
34183418
// rewrite result of `node`.
@@ -3451,7 +3451,14 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
34513451
inferenceLogWriter?.enterExpression(node, contextType);
34523452
checkUnreachableNode(node);
34533453

3454-
_resolvePropertyAccess(node, contextType);
3454+
var target = node.target;
3455+
if (target != null) {
3456+
analyzeExpression(
3457+
target, SharedTypeSchemaView(UnknownInferredType.instance));
3458+
popRewrite();
3459+
}
3460+
3461+
_resolvePropertyAccessRhs(node, contextType);
34553462
inferenceLogWriter?.exitExpression(node);
34563463
}
34573464

@@ -4086,14 +4093,8 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
40864093
callReference.setPseudoExpressionStaticType(callMethodType);
40874094
}
40884095

4089-
void _resolvePropertyAccess(PropertyAccessImpl node, DartType contextType) {
4090-
var target = node.target;
4091-
if (target != null) {
4092-
analyzeExpression(
4093-
target, SharedTypeSchemaView(UnknownInferredType.instance));
4094-
popRewrite();
4095-
}
4096-
4096+
void _resolvePropertyAccessRhs(
4097+
PropertyAccessImpl node, DartType contextType) {
40974098
if (node.isNullAware) {
40984099
_startNullAwareAccess(node, node.target);
40994100
}

0 commit comments

Comments
 (0)