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' show max;
86
97import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart'
108 show Variance;
11- import 'package:analyzer/dart/element/element .dart' ;
9+ import 'package:analyzer/dart/element/element2 .dart' ;
1210import 'package:analyzer/dart/element/nullability_suffix.dart' ;
1311import 'package:analyzer/dart/element/type.dart' ;
1412import 'package:analyzer/src/dart/element/extensions.dart' ;
@@ -61,10 +59,10 @@ class InterfaceLeastUpperBoundHelper {
6159 return type1.withNullability (nullability);
6260 }
6361
64- if (type1.element == type2.element ) {
62+ if (type1.element3 == type2.element3 ) {
6563 var args1 = type1.typeArguments;
6664 var args2 = type2.typeArguments;
67- var params = type1.element.typeParameters ;
65+ var params = type1.element3.typeParameters2 ;
6866 assert (args1.length == args2.length);
6967 assert (args1.length == params.length);
7068
@@ -93,8 +91,8 @@ class InterfaceLeastUpperBoundHelper {
9391 }
9492 }
9593
96- return InterfaceTypeImpl (
97- element: type1.element ,
94+ return InterfaceTypeImpl . v2 (
95+ element: type1.element3 ,
9896 typeArguments: args,
9997 nullabilitySuffix: nullability,
10098 );
@@ -124,7 +122,7 @@ class InterfaceLeastUpperBoundHelper {
124122 return ;
125123 }
126124
127- if (type.element is ExtensionTypeElement ) {
125+ if (type.element3 is ExtensionTypeElement2 ) {
128126 set .add (typeSystem.objectQuestion);
129127 }
130128
@@ -180,7 +178,7 @@ class InterfaceLeastUpperBoundHelper {
180178 /// Object.
181179 @visibleForTesting
182180 static int computeLongestInheritancePathToObject (InterfaceType type) {
183- return _computeLongestInheritancePathToObject (type, < InterfaceElement > {});
181+ return _computeLongestInheritancePathToObject (type, < InterfaceElement2 > {});
184182 }
185183
186184 static NullabilitySuffix _chooseNullability (
@@ -202,8 +200,8 @@ class InterfaceLeastUpperBoundHelper {
202200 /// The set of [visitedElements] is used to prevent infinite recursion in the
203201 /// case of a cyclic type structure.
204202 static int _computeLongestInheritancePathToObject (
205- InterfaceType type, Set <InterfaceElement > visitedElements) {
206- var element = type.element ;
203+ InterfaceType type, Set <InterfaceElement2 > visitedElements) {
204+ var element = type.element3 ;
207205 // recursion
208206 if (visitedElements.contains (element)) {
209207 return 0 ;
@@ -213,14 +211,14 @@ class InterfaceLeastUpperBoundHelper {
213211 return 1 ;
214212 }
215213 // Object case
216- if (element is ClassElement ) {
214+ if (element is ClassElement2 ) {
217215 if (element.isDartCoreObject) {
218216 return type.nullabilitySuffix == NullabilitySuffix .none ? 1 : 0 ;
219217 }
220218 }
221219
222220 // Extension type without interfaces, implicit `Object?`
223- if (element is ExtensionTypeElement ) {
221+ if (element is ExtensionTypeElement2 ) {
224222 if (element.interfaces.isEmpty) {
225223 return 1 ;
226224 }
@@ -232,7 +230,7 @@ class InterfaceLeastUpperBoundHelper {
232230
233231 // loop through each of the superinterfaces recursively calling this
234232 // method and keeping track of the longest path to return
235- if (element is MixinElement ) {
233+ if (element is MixinElement2 ) {
236234 for (InterfaceType interface in element.superclassConstraints) {
237235 var pathLength = _computeLongestInheritancePathToObject (
238236 interface , visitedElements);
@@ -248,7 +246,7 @@ class InterfaceLeastUpperBoundHelper {
248246 longestPath = max (longestPath, 1 + pathLength);
249247 }
250248
251- if (element is ! ClassElement ) {
249+ if (element is ! ClassElement2 ) {
252250 return longestPath;
253251 }
254252
@@ -321,7 +319,7 @@ class LeastUpperBoundHelper {
321319 LeastUpperBoundHelper (this ._typeSystem);
322320
323321 InterfaceType get _interfaceTypeFunctionNone {
324- return _typeSystem.typeProvider.functionType.element .instantiate (
322+ return _typeSystem.typeProvider.functionType.element3 .instantiate (
325323 typeArguments: const [],
326324 nullabilitySuffix: NullabilitySuffix .none,
327325 );
@@ -625,8 +623,8 @@ class LeastUpperBoundHelper {
625623 /// https://github.com/dart-lang/language
626624 /// See `resources/type-system/upper-lower-bounds.md`
627625 DartType _functionType (FunctionType f, FunctionType g) {
628- var fTypeFormals = f.typeFormals ;
629- var gTypeFormals = g.typeFormals ;
626+ var fTypeFormals = f.typeParameters ;
627+ var gTypeFormals = g.typeParameters ;
630628
631629 // The number of type parameters must be the same.
632630 // Otherwise the result is `Function`.
@@ -636,18 +634,21 @@ class LeastUpperBoundHelper {
636634
637635 // The bounds of type parameters must be equal.
638636 // Otherwise the result is `Function`.
639- var fresh = _typeSystem.relateTypeParameters (f.typeFormals, g.typeFormals);
637+ var fresh = _typeSystem.relateTypeParameters2 (
638+ f.typeParameters,
639+ g.typeParameters,
640+ );
640641 if (fresh == null ) {
641642 return _interfaceTypeFunctionNone;
642643 }
643644
644645 f = f.instantiate (fresh.typeParameterTypes);
645646 g = g.instantiate (fresh.typeParameterTypes);
646647
647- var fParameters = f.parameters ;
648- var gParameters = g.parameters ;
648+ var fParameters = f.formalParameters ;
649+ var gParameters = g.formalParameters ;
649650
650- var parameters = < ParameterElement > [];
651+ var parameters = < FormalParameterElement > [];
651652 var fIndex = 0 ;
652653 var gIndex = 0 ;
653654 while (fIndex < fParameters.length && gIndex < gParameters.length) {
@@ -679,7 +680,13 @@ class LeastUpperBoundHelper {
679680 }
680681 } else if (fParameter.isNamed) {
681682 if (gParameter.isNamed) {
682- var compareNames = fParameter.name.compareTo (gParameter.name);
683+ var fName = fParameter.name3;
684+ var gName = gParameter.name3;
685+ if (fName == null || gName == null ) {
686+ return _interfaceTypeFunctionNone;
687+ }
688+
689+ var compareNames = fName.compareTo (gName);
683690 if (compareNames == 0 ) {
684691 fIndex++ ;
685692 gIndex++ ;
@@ -729,9 +736,9 @@ class LeastUpperBoundHelper {
729736
730737 var returnType = getLeastUpperBound (f.returnType, g.returnType);
731738
732- return FunctionTypeImpl (
733- typeFormals : fresh.typeParameters,
734- parameters : parameters,
739+ return FunctionTypeImpl . v2 (
740+ typeParameters : fresh.typeParameters,
741+ formalParameters : parameters,
735742 returnType: returnType,
736743 nullabilitySuffix: NullabilitySuffix .none,
737744 );
@@ -787,7 +794,7 @@ class LeastUpperBoundHelper {
787794 return null ;
788795 }
789796
790- DartType _parameterType (ParameterElement a, ParameterElement b) {
797+ DartType _parameterType (FormalParameterElement a, FormalParameterElement b) {
791798 return _typeSystem.greatestLowerBound (a.type, b.type);
792799 }
793800
@@ -841,7 +848,7 @@ class LeastUpperBoundHelper {
841848
842849 /// Return the promoted or declared bound of the type parameter.
843850 DartType _typeParameterBound (TypeParameterTypeImpl type) {
844- var bound = type.promotedBound ?? type.element .bound;
851+ var bound = type.promotedBound ?? type.element3 .bound;
845852 if (bound != null ) {
846853 return bound;
847854 }
0 commit comments