@@ -6,11 +6,10 @@ import 'package:analyzer/dart/ast/ast.dart';
66import 'package:analyzer/dart/ast/syntactic_entity.dart' ;
77import 'package:analyzer/dart/ast/token.dart' ;
88import 'package:analyzer/dart/ast/visitor.dart' ;
9- import 'package:analyzer/dart/element/element .dart' ;
9+ import 'package:analyzer/dart/element/element2 .dart' ;
1010import 'package:analyzer/dart/element/type.dart' ;
1111import 'package:analyzer/error/listener.dart' ;
1212import 'package:analyzer/src/dart/ast/ast.dart' ;
13- import 'package:analyzer/src/dart/element/element.dart' ;
1413import '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