Skip to content

Commit 5dc11bf

Browse files
scheglovCommit Queue
authored andcommitted
Elements. Migrate ConstArgumentsVerifier.
Change-Id: I16411e4e39de0dcc5be83ed6861189742c3f61ac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395163 Reviewed-by: Phil Quitslund <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 4475a23 commit 5dc11bf

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

pkg/analyzer/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ lib/src/diagnostic/diagnostic_factory.dart
101101
lib/src/error/assignment_verifier.dart
102102
lib/src/error/base_or_final_type_verifier.dart
103103
lib/src/error/best_practices_verifier.dart
104-
lib/src/error/const_argument_verifier.dart
105104
lib/src/error/constructor_fields_verifier.dart
106105
lib/src/error/correct_override.dart
107106
lib/src/error/dead_code_verifier.dart

pkg/analyzer/lib/src/error/const_argument_verifier.dart

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/syntactic_entity.dart';
77
import 'package:analyzer/dart/ast/token.dart';
88
import 'package:analyzer/dart/ast/visitor.dart';
9-
import 'package:analyzer/dart/element/element.dart';
9+
import 'package:analyzer/dart/element/element2.dart';
1010
import 'package:analyzer/dart/element/type.dart';
1111
import 'package:analyzer/error/listener.dart';
1212
import 'package:analyzer/src/dart/ast/ast.dart';
13-
import 'package:analyzer/src/dart/element/element.dart';
1413
import 'package:analyzer/src/error/codes.dart';
1514

1615
/// Checks if the arguments for a parameter annotated with `@mustBeConst` are
@@ -27,7 +26,8 @@ class ConstArgumentsVerifier extends SimpleAstVisitor<void> {
2726
arguments: [node.rightHandSide],
2827
errorNode: node.operator,
2928
);
30-
} else if (node.rightHandSide.staticParameterElement?.hasMustBeConst ??
29+
} else if (node
30+
.rightHandSide.correspondingParameter?.metadata2.hasMustBeConst ??
3131
false) {
3232
// If the operator is not `=`, then the argument cannot be const, as it
3333
// depends on the value of the left hand side.
@@ -104,8 +104,17 @@ class ConstArgumentsVerifier extends SimpleAstVisitor<void> {
104104
required SyntacticEntity errorNode,
105105
}) {
106106
for (var argument in arguments) {
107-
var parameter = argument.staticParameterElement;
108-
if (parameter != null && parameter.hasMustBeConst) {
107+
var parameter = argument.correspondingParameter;
108+
if (parameter == null) {
109+
continue;
110+
}
111+
112+
var parameterName = parameter.name3;
113+
if (parameterName == null) {
114+
continue;
115+
}
116+
117+
if (parameter.metadata2.hasMustBeConst) {
109118
Expression resolvedArgument;
110119
if (parameter.isNamed) {
111120
resolvedArgument = (argument as NamedExpression).expression;
@@ -116,7 +125,7 @@ class ConstArgumentsVerifier extends SimpleAstVisitor<void> {
116125
_errorReporter.atNode(
117126
argument,
118127
WarningCode.NON_CONST_ARGUMENT_FOR_CONST_PARAMETER,
119-
arguments: [parameter.name],
128+
arguments: [parameterName],
120129
);
121130
}
122131
}
@@ -143,12 +152,12 @@ class ConstArgumentsVerifier extends SimpleAstVisitor<void> {
143152
StringInterpolation() => false,
144153
};
145154
} else if (expression is Identifier) {
146-
var staticElement = expression.staticElement;
147-
if (staticElement != null) {
148-
if ((staticElement is VariableElement && staticElement.isConst) ||
149-
staticElement.nonSynthetic is ConstVariableElement) {
150-
return true;
151-
}
155+
var element = expression.element;
156+
switch (element) {
157+
case GetterElement(variable3: var variable?):
158+
return variable.isConst;
159+
case VariableElement2():
160+
return element.isConst;
152161
}
153162
}
154163
return false;

0 commit comments

Comments
 (0)