22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // ignore_for_file: analyzer_use_new_elements
6-
75import 'dart:math' as math;
86
97import 'package:_fe_analyzer_shared/src/type_inference/shared_inference_log.dart' ;
108import 'package:_fe_analyzer_shared/src/types/shared_type.dart' ;
119import 'package:analyzer/dart/ast/syntactic_entity.dart' ;
12- import 'package:analyzer/dart/element/element.dart' ;
1310import 'package:analyzer/dart/element/element2.dart' ;
1411import 'package:analyzer/dart/element/type.dart' ;
1512import 'package:analyzer/error/listener.dart' show ErrorReporter;
@@ -26,7 +23,6 @@ import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
2623import 'package:analyzer/src/error/codes.dart'
2724 show CompileTimeErrorCode, WarningCode;
2825import 'package:analyzer/src/generated/inference_log.dart' ;
29- import 'package:analyzer/src/utilities/extensions/element.dart' ;
3026import 'package:collection/collection.dart' ;
3127
3228/// Tracks upper and lower type bounds for a set of type parameters.
@@ -149,7 +145,8 @@ class GenericInferrer {
149145 /// type is a subtype of the [parameterType] .
150146 void constrainArgument (
151147 TypeImpl argumentType, TypeImpl parameterType, String parameterName,
152- {InterfaceElement ? genericClass, required AstNodeImpl ? nodeForTesting}) {
148+ {InterfaceElementImpl ? genericClass,
149+ required AstNodeImpl ? nodeForTesting}) {
153150 var origin = TypeConstraintFromArgument (
154151 argumentType: SharedTypeView (argumentType),
155152 parameterType: SharedTypeView (parameterType),
@@ -167,7 +164,7 @@ class GenericInferrer {
167164 /// Applies all the argument constraints implied by [parameters] and
168165 /// [argumentTypes] .
169166 void constrainArguments (
170- {InterfaceElement ? genericClass,
167+ {InterfaceElementImpl ? genericClass,
171168 required List <ParameterElementMixin > parameters,
172169 required List <TypeImpl > argumentTypes,
173170 required AstNodeImpl ? nodeForTesting}) {
@@ -187,7 +184,7 @@ class GenericInferrer {
187184 /// Applies all the argument constraints implied by [parameters] and
188185 /// [argumentTypes] .
189186 void constrainArguments2 (
190- {InterfaceElement ? genericClass,
187+ {InterfaceElementImpl ? genericClass,
191188 required List <FormalParameterElementMixin > parameters,
192189 required List <TypeImpl > argumentTypes,
193190 required AstNodeImpl ? nodeForTesting}) {
@@ -560,7 +557,7 @@ class GenericInferrer {
560557 }
561558 }
562559
563- String _elementStr (Element element) {
560+ String _elementStr (ElementImpl element) {
564561 return element.getDisplayString ();
565562 }
566563
@@ -719,7 +716,7 @@ class GenericInferrer {
719716 } else if (errorEntity is Annotation ) {
720717 if (genericMetadataIsEnabled) {
721718 // Only report an error if generic metadata is valid syntax.
722- var element = errorEntity.name.element? .asElement ;
719+ var element = errorEntity.name.element;
723720 if (element != null && ! element.hasOptionalTypeArgs) {
724721 String constructorName = errorEntity.constructorName == null
725722 ? errorEntity.name.name
@@ -732,9 +729,9 @@ class GenericInferrer {
732729 }
733730 }
734731 } else if (errorEntity is SimpleIdentifier ) {
735- var element = errorEntity.element? .asElement ;
732+ var element = errorEntity.element;
736733 if (element != null ) {
737- if (element is VariableElement ) {
734+ if (element is VariableElement2 ) {
738735 // For variable elements, we check their type and possible alias type.
739736 var type = element.type;
740737 var typeElement = type is InterfaceType ? type.element3 : null ;
@@ -861,3 +858,12 @@ class GenericInferrer {
861858 return messageLines.join ('\n ' );
862859 }
863860}
861+
862+ extension on Element2 {
863+ bool get hasOptionalTypeArgs {
864+ if (this case Annotatable annotatable) {
865+ return annotatable.metadata2.hasOptionalTypeArgs;
866+ }
867+ return false ;
868+ }
869+ }
0 commit comments