Skip to content

Commit a56b0d6

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Use ExpressionImpl when interfacing with shared code
Change the analyzer's use of the following generic types so that it supplies the type parameter `ExpressionImpl` instead of `Expression` as the type of AST node it uses to represent expressions: - `CaseHeadOrDefaultInfo` - `FlowAnalysis` - `MapPatternEntry` - `MatchContext` - `NullShortingMixin` - `PropertyTarget` - `SwitchExpressionMemberInfo` - `SwitchStatementMemberInfo` - `TypeAnalyzer` - `TypeAnalyzerErrors` This required adjusting some type casts and `is` tests to test against concrete expression types instead of abstract public interface types (e.g. `as SimpleIdentifierImpl` instead of `as SimpleIdentifier`). In some places I was able to avoid adding casts by changing method parameters to accept concrete statement types instead of abstract public interface types. This required adding the `covariant` keyword to some methods. This is part of a larger arc of work to change the analyzer's use of the shared code so that the type parameters it supplies are not part of the analyzer public API. See #59763. Change-Id: Ib33f0f5b3b30bfe2554316b5aa7c11524b63bcd3 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403161 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 8191171 commit a56b0d6

19 files changed

+111
-110
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class AssignmentExpressionResolver {
8585
var leftType = node.writeType;
8686
if (writeElement is VariableElement) {
8787
leftType = _resolver.localVariableTypeProvider
88-
.getType(left as SimpleIdentifier, isRead: false);
88+
.getType(left as SimpleIdentifierImpl, isRead: false);
8989
}
9090
rhsContext = _computeRhsContext(node, leftType!, operator, right);
9191
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,9 @@ class BinaryExpressionResolver {
406406
String methodName, {
407407
bool promoteLeftTypeToNonNull = false,
408408
}) {
409-
Expression leftOperand = node.leftOperand;
409+
ExpressionImpl leftOperand = node.leftOperand;
410410

411-
if (leftOperand is ExtensionOverride) {
411+
if (leftOperand is ExtensionOverrideImpl) {
412412
var extension = leftOperand.element;
413413
var member = extension.getMethod(methodName);
414414
if (member == null) {

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class FlowAnalysisHelper {
9696
final bool inferenceUpdate4Enabled;
9797

9898
/// The current flow, when resolving a function body, or `null` otherwise.
99-
FlowAnalysis<AstNode, StatementImpl, Expression, PromotableElementImpl2,
99+
FlowAnalysis<AstNode, StatementImpl, ExpressionImpl, PromotableElementImpl2,
100100
SharedTypeView<DartType>>? flow;
101101

102102
FlowAnalysisHelper(bool retainDataForTesting, FeatureSet featureSet,
@@ -126,7 +126,7 @@ class FlowAnalysisHelper {
126126
return _LocalVariableTypeProvider(this);
127127
}
128128

129-
void asExpression(AsExpression node) {
129+
void asExpression(AsExpressionImpl node) {
130130
if (flow == null) return;
131131

132132
var expression = node.expression;
@@ -136,7 +136,7 @@ class FlowAnalysisHelper {
136136
expression, SharedTypeView(typeAnnotation.typeOrThrow));
137137
}
138138

139-
void assignmentExpression(AssignmentExpression node) {
139+
void assignmentExpression(AssignmentExpressionImpl node) {
140140
if (flow == null) return;
141141

142142
if (node.operator.type == TokenType.QUESTION_QUESTION_EQ) {
@@ -177,7 +177,7 @@ class FlowAnalysisHelper {
177177
as AssignedVariablesForTesting<AstNode, PromotableElementImpl2>;
178178
}
179179
flow = isNonNullableByDefault
180-
? FlowAnalysis<AstNode, StatementImpl, Expression,
180+
? FlowAnalysis<AstNode, StatementImpl, ExpressionImpl,
181181
PromotableElementImpl2, SharedTypeView<DartType>>(
182182
typeOperations,
183183
assignedVariables!,
@@ -186,7 +186,7 @@ class FlowAnalysisHelper {
186186
fieldPromotionEnabled: fieldPromotionEnabled,
187187
inferenceUpdate4Enabled: inferenceUpdate4Enabled,
188188
)
189-
: FlowAnalysis<AstNode, StatementImpl, Expression,
189+
: FlowAnalysis<AstNode, StatementImpl, ExpressionImpl,
190190
PromotableElementImpl2, SharedTypeView<DartType>>.legacy(
191191
typeOperations, assignedVariables!);
192192
}
@@ -257,7 +257,7 @@ class FlowAnalysisHelper {
257257
}
258258
}
259259

260-
void for_bodyBegin(AstNode node, Expression? condition) {
260+
void for_bodyBegin(AstNode node, ExpressionImpl? condition) {
261261
flow?.for_bodyBegin(node is StatementImpl ? node : null, condition);
262262
}
263263

@@ -295,7 +295,7 @@ class FlowAnalysisHelper {
295295
return isUnassigned;
296296
}
297297

298-
void isExpression(IsExpression node) {
298+
void isExpression(IsExpressionImpl node) {
299299
if (flow == null) return;
300300

301301
var expression = node.expression;
@@ -1198,7 +1198,7 @@ class _LocalVariableTypeProvider implements LocalVariableTypeProvider {
11981198
_LocalVariableTypeProvider(this._manager);
11991199

12001200
@override
1201-
DartType getType(SimpleIdentifier node, {required bool isRead}) {
1201+
DartType getType(SimpleIdentifierImpl node, {required bool isRead}) {
12021202
var variable = node.element as VariableElement2;
12031203
if (variable is PromotableElementImpl2) {
12041204
var promotedType = isRead

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,15 @@ class ForResolver {
120120
return iteratedType.typeArguments.single;
121121
}
122122

123-
void _forEachParts(AstNode node, bool isAsync, ForEachParts forEachParts,
123+
void _forEachParts(AstNode node, bool isAsync, ForEachPartsImpl forEachParts,
124124
void Function() visitBody) {
125-
Expression iterable = forEachParts.iterable;
125+
ExpressionImpl iterable = forEachParts.iterable;
126126
DeclaredIdentifierImpl? loopVariable;
127-
SimpleIdentifier? identifier;
127+
SimpleIdentifierImpl? identifier;
128128
Element2? identifierElement;
129129
if (forEachParts is ForEachPartsWithDeclarationImpl) {
130130
loopVariable = forEachParts.loopVariable;
131-
} else if (forEachParts is ForEachPartsWithIdentifier) {
131+
} else if (forEachParts is ForEachPartsWithIdentifierImpl) {
132132
identifier = forEachParts.identifier;
133133
// TODO(scheglov): replace with lexical lookup
134134
inferenceLogWriter?.setExpressionVisitCodePath(
@@ -199,16 +199,17 @@ class ForResolver {
199199
_resolver.flowAnalysis.flow?.forEach_end();
200200
}
201201

202-
void _forParts(AstNode node, ForParts forParts, void Function() visitBody) {
203-
if (forParts is ForPartsWithDeclarations) {
202+
void _forParts(
203+
AstNode node, ForPartsImpl forParts, void Function() visitBody) {
204+
if (forParts is ForPartsWithDeclarationsImpl) {
204205
forParts.variables.accept(_resolver);
205-
} else if (forParts is ForPartsWithExpression) {
206+
} else if (forParts is ForPartsWithExpressionImpl) {
206207
if (forParts.initialization case var initialization?) {
207208
_resolver.analyzeExpression(
208209
initialization, _resolver.operations.unknownType);
209210
_resolver.popRewrite();
210211
}
211-
} else if (forParts is ForPartsWithPattern) {
212+
} else if (forParts is ForPartsWithPatternImpl) {
212213
forParts.variables.accept(_resolver);
213214
} else {
214215
throw StateError('Unrecognized for loop parts');

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ class FunctionReferenceResolver {
391391
/// function element, tearing off an extension element declared on [Function],
392392
/// and tearing off an extension element declared on a function type.
393393
Element? _resolveFunctionTypeFunction(
394-
Expression receiver,
394+
ExpressionImpl receiver,
395395
SimpleIdentifier methodName,
396396
FunctionType receiverType,
397397
) {
@@ -869,11 +869,11 @@ class FunctionReferenceResolver {
869869
/// Returns `null` if [receiver]'s type is `null`, a [TypeParameterType],
870870
/// or a type alias for a non-interface type.
871871
DartType? _resolveTypeProperty({
872-
required Expression receiver,
872+
required ExpressionImpl receiver,
873873
required SimpleIdentifierImpl name,
874874
required SyntacticEntity nameErrorEntity,
875875
}) {
876-
if (receiver is Identifier) {
876+
if (receiver is IdentifierImpl) {
877877
var receiverElement = receiver.staticElement;
878878
if (receiverElement is InterfaceElement) {
879879
var element = _resolveStaticElement(receiverElement, name);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ class InvocationInferrer<Node extends AstNodeImpl> {
483483
var leftOperandInfo = identicalArgumentInfo[0]!;
484484
var rightOperandInfo = identicalArgumentInfo[1]!;
485485
flow?.equalityOperation_end(
486-
argumentList.parent as Expression,
486+
argumentList.parent as ExpressionImpl,
487487
leftOperandInfo.expressionInfo,
488488
SharedTypeView<DartType>(leftOperandInfo.staticType),
489489
rightOperandInfo.expressionInfo,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ class MethodInvocationResolver with ScopeHelpers {
499499
/// process, then returns that new node. Otherwise, returns `null`.
500500
FunctionExpressionInvocationImpl? _resolveReceiverNever(
501501
MethodInvocationImpl node,
502-
Expression receiver,
502+
ExpressionImpl receiver,
503503
DartType receiverType,
504504
List<WhyNotPromotedGetter> whyNotPromotedArguments, {
505505
required DartType contextType,
@@ -804,7 +804,7 @@ class MethodInvocationResolver with ScopeHelpers {
804804
/// process, then returns that new node. Otherwise, returns `null`.
805805
FunctionExpressionInvocationImpl? _resolveReceiverType({
806806
required MethodInvocationImpl node,
807-
required Expression? receiver,
807+
required ExpressionImpl? receiver,
808808
required DartType receiverType,
809809
required SimpleIdentifierImpl nameNode,
810810
required String name,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class PostfixExpressionResolver {
124124
}
125125

126126
void _resolve1(PostfixExpressionImpl node, DartType receiverType) {
127-
Expression operand = node.operand;
127+
ExpressionImpl operand = node.operand;
128128

129129
if (identical(receiverType, NeverTypeImpl.instance)) {
130130
_resolver.errorReporter.atNode(

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ class PrefixExpressionResolver {
153153
TokenType operatorType = operator.type;
154154
if (operatorType.isUserDefinableOperator ||
155155
operatorType.isIncrementOperator) {
156-
Expression operand = node.operand;
156+
ExpressionImpl operand = node.operand;
157157
String methodName = _getPrefixOperator(node);
158-
if (operand is ExtensionOverride) {
158+
if (operand is ExtensionOverrideImpl) {
159159
var element = operand.element;
160160
var member = element.getMethod(methodName);
161161
if (member == null) {

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ class PropertyElementResolver with ScopeHelpers {
4141
TypeSystemImpl get _typeSystem => _resolver.typeSystem;
4242

4343
PropertyElementResolverResult resolveIndexExpression({
44-
required IndexExpression node,
44+
required IndexExpressionImpl node,
4545
required bool hasRead,
4646
required bool hasWrite,
4747
}) {
4848
var target = node.realTarget;
4949

50-
if (target is ExtensionOverride) {
50+
if (target is ExtensionOverrideImpl) {
5151
var result = _extensionResolver.getOverrideMember(target, '[]');
5252

5353
// TODO(scheglov): Change ExtensionResolver to set `needsGetterError`.
@@ -149,7 +149,7 @@ class PropertyElementResolver with ScopeHelpers {
149149
}
150150

151151
PropertyElementResolverResult resolvePrefixedIdentifier({
152-
required PrefixedIdentifier node,
152+
required PrefixedIdentifierImpl node,
153153
required bool hasRead,
154154
required bool hasWrite,
155155
bool forAnnotation = false,
@@ -180,14 +180,14 @@ class PropertyElementResolver with ScopeHelpers {
180180
}
181181

182182
PropertyElementResolverResult resolvePropertyAccess({
183-
required PropertyAccess node,
183+
required PropertyAccessImpl node,
184184
required bool hasRead,
185185
required bool hasWrite,
186186
}) {
187187
var target = node.realTarget;
188188
var propertyName = node.propertyName;
189189

190-
if (target is ExtensionOverride) {
190+
if (target is ExtensionOverrideImpl) {
191191
return _resolveTargetExtensionOverride(
192192
target: target,
193193
propertyName: propertyName,
@@ -196,7 +196,7 @@ class PropertyElementResolver with ScopeHelpers {
196196
);
197197
}
198198

199-
if (target is SuperExpression) {
199+
if (target is SuperExpressionImpl) {
200200
return _resolveTargetSuperExpression(
201201
node: node,
202202
target: target,
@@ -388,8 +388,8 @@ class PropertyElementResolver with ScopeHelpers {
388388
}
389389

390390
PropertyElementResolverResult _resolve({
391-
required Expression node,
392-
required Expression target,
391+
required ExpressionImpl node,
392+
required ExpressionImpl target,
393393
required bool isCascaded,
394394
required bool isNullAware,
395395
required SimpleIdentifier propertyName,
@@ -402,7 +402,7 @@ class PropertyElementResolver with ScopeHelpers {
402402
// hierarchy, instead we just look for the member in the type only. This
403403
// does not apply to conditional property accesses (i.e. 'C?.m').
404404
//
405-
if (target is Identifier) {
405+
if (target is IdentifierImpl) {
406406
var targetElement = target.staticElement;
407407
if (targetElement is InterfaceElement) {
408408
return _resolveTargetInterfaceElement(
@@ -431,7 +431,7 @@ class PropertyElementResolver with ScopeHelpers {
431431
// then look for the member in the extension. This does not apply to
432432
// conditional property accesses (i.e. 'C?.m').
433433
//
434-
if (target is Identifier) {
434+
if (target is IdentifierImpl) {
435435
var targetElement = target.staticElement;
436436
if (targetElement is ExtensionElement) {
437437
return _resolveTargetExtensionElement(
@@ -465,7 +465,7 @@ class PropertyElementResolver with ScopeHelpers {
465465
targetType = _typeSystem.promoteToNonNull(targetType);
466466
}
467467

468-
if (target is TypeLiteral && target.type.type is FunctionType) {
468+
if (target is TypeLiteralImpl && target.type.type is FunctionType) {
469469
// There is no possible resolution for a property access of a function
470470
// type literal (which can only be a type instantiation of a type alias
471471
// of a function type).
@@ -505,7 +505,7 @@ class PropertyElementResolver with ScopeHelpers {
505505
node,
506506
isCascaded
507507
? CascadePropertyTarget.singleton
508-
as PropertyTarget<Expression>
508+
as PropertyTarget<ExpressionImpl>
509509
: ExpressionPropertyTarget(target),
510510
propertyName.name,
511511
result.getter,
@@ -796,7 +796,7 @@ class PropertyElementResolver with ScopeHelpers {
796796
}
797797

798798
PropertyElementResolverResult _resolveTargetSuperExpression({
799-
required Expression node,
799+
required ExpressionImpl node,
800800
required SuperExpression target,
801801
required SimpleIdentifier propertyName,
802802
required bool hasRead,

0 commit comments

Comments
 (0)