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-
7- import 'package:analyzer/dart/element/element.dart' ;
85import 'package:analyzer/dart/element/nullability_suffix.dart' ;
96import 'package:analyzer/dart/element/type.dart' ;
107import 'package:analyzer/src/dart/ast/ast.dart' ;
@@ -34,15 +31,15 @@ class FunctionExpressionResolver {
3431 .executableDeclaration_enter (node, node.parameters, isClosure: true );
3532 }
3633
37- bool wasFunctionTypeSupplied = contextType is FunctionType ;
34+ bool wasFunctionTypeSupplied = contextType is FunctionTypeImpl ;
3835 node.wasFunctionTypeSupplied = wasFunctionTypeSupplied;
3936 DartType ? imposedType;
4037 if (wasFunctionTypeSupplied) {
4138 var instantiatedType = _matchTypeParameters (
4239 node.typeParameters,
4340 contextType,
4441 );
45- if (instantiatedType is FunctionType ) {
42+ if (instantiatedType is FunctionTypeImpl ) {
4643 _inferFormalParameters (node.parameters, instantiatedType);
4744 var returnType = instantiatedType.returnType;
4845 if (! (returnType is DynamicType || returnType is UnknownInferredType )) {
@@ -82,7 +79,7 @@ class FunctionExpressionResolver {
8279 return ;
8380 }
8481
85- void inferType (ParameterElementImpl p, TypeImpl inferredType) {
82+ void inferType (FormalParameterElementImpl p, TypeImpl inferredType) {
8683 // Check that there is no declared type, and that we have not already
8784 // inferred a type in some fashion.
8885 if (p.hasImplicitType && p.type is DynamicType ) {
@@ -98,39 +95,45 @@ class FunctionExpressionResolver {
9895 inferredType = _typeSystem.objectQuestion;
9996 }
10097 if (inferredType is ! DynamicType ) {
101- p.type = inferredType;
98+ p.firstFragment. type = inferredType;
10299 }
103100 }
104101 }
105102
106- var parameters = node.parameterElements .nonNulls;
103+ var nodeParameterFragments = node.parameterFragments .nonNulls;
107104 {
108- Iterator <ParameterElement > positional =
109- parameters.where ((p) => p.isPositional).iterator;
110- Iterator <ParameterElement > fnPositional =
111- contextType.parameters.where ((p) => p.isPositional).iterator;
112- while (positional.moveNext () && fnPositional.moveNext ()) {
105+ var nodePositional = nodeParameterFragments
106+ .map ((fragment) => fragment.element)
107+ .where ((element) => element.isPositional)
108+ .iterator;
109+ var contextPositional = contextType.formalParameters
110+ .where ((element) => element.isPositional)
111+ .iterator;
112+ while (nodePositional.moveNext () && contextPositional.moveNext ()) {
113113 inferType (
114- positional.current as ParameterElementImpl ,
115- // TODO(paulberry): eliminate this cast by changing the type of
116- // `contextType` to `FunctionTypeImpl`.
117- fnPositional.current.type as TypeImpl );
114+ nodePositional.current as FormalParameterElementImpl ,
115+ // TODO(paulberry): eliminate this cast by changing the type of
116+ // `contextType` to `FunctionTypeImpl`.
117+ contextPositional.current.type as TypeImpl ,
118+ );
118119 }
119120 }
120121
121122 {
122- Map <String , DartType > namedParameterTypes =
123- contextType.namedParameterTypes;
124- Iterable <ParameterElement > named = parameters.where ((p) => p.isNamed);
125- for (var p in named) {
126- if (! namedParameterTypes.containsKey (p.name)) {
123+ var contextNamedTypes = contextType.namedParameterTypes;
124+ var nodeNamed = nodeParameterFragments
125+ .map ((fragment) => fragment.element)
126+ .where ((element) => element.isNamed);
127+ for (var element in nodeNamed) {
128+ if (! contextNamedTypes.containsKey (element.name3)) {
127129 continue ;
128130 }
129131 inferType (
130- p as ParameterElementImpl ,
131- // TODO(paulberry): eliminate this cast by changing the type of
132- // `contextType` to `FunctionTypeImpl`.
133- namedParameterTypes[p.name]! as TypeImpl );
132+ element as FormalParameterElementImpl ,
133+ // TODO(paulberry): eliminate this cast by changing the type of
134+ // `contextType` to `FunctionTypeImpl`.
135+ contextNamedTypes[element.name3]! as TypeImpl ,
136+ );
134137 }
135138 }
136139 }
@@ -140,32 +143,35 @@ class FunctionExpressionResolver {
140143 ///
141144 /// Return `null` is the number of element in [typeParameterList] is not
142145 /// the same as the number of type parameters in the [type] .
143- FunctionType ? _matchTypeParameters (
144- TypeParameterList ? typeParameterList, FunctionType type) {
146+ FunctionTypeImpl ? _matchTypeParameters (
147+ TypeParameterListImpl ? typeParameterList, FunctionTypeImpl type) {
145148 if (typeParameterList == null ) {
146- if (type.typeFormals .isEmpty) {
149+ if (type.typeParameters .isEmpty) {
147150 return type;
148151 }
149152 return null ;
150153 }
151154
152155 var typeParameters = typeParameterList.typeParameters;
153- if (typeParameters.length != type.typeFormals .length) {
156+ if (typeParameters.length != type.typeParameters .length) {
154157 return null ;
155158 }
156159
157160 return type.instantiate (typeParameters.map ((typeParameter) {
158- return typeParameter.declaredElement ! .instantiate (
161+ return typeParameter.declaredFragment ! .element .instantiate (
159162 nullabilitySuffix: NullabilitySuffix .none,
160163 );
161164 }).toList ());
162165 }
163166
164167 void _resolve2 (FunctionExpressionImpl node, DartType ? imposedType) {
165- var functionElement = node.declaredElement as ExecutableElementImpl ;
168+ var functionElement =
169+ node.declaredFragment! .element as ExecutableElementImpl2 ;
166170
167171 if (_shouldUpdateReturnType (node)) {
168- functionElement.returnType = imposedType ?? DynamicTypeImpl .instance;
172+ var firstFragment =
173+ functionElement.firstFragment as ExecutableElementImpl ;
174+ firstFragment.returnType = imposedType ?? DynamicTypeImpl .instance;
169175 }
170176
171177 node.recordStaticType (functionElement.type, resolver: _resolver);
0 commit comments