Skip to content

Commit 0ddaa63

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate generic_inferrer_test
Change-Id: Ie626f94ea74f6d07be517d87c0f0a4a3dda00feb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405446 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 6b56a41 commit 0ddaa63

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

pkg/analyzer/lib/src/dart/element/generic_inferrer.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,26 @@ class GenericInferrer {
183183
}
184184
}
185185

186+
/// Applies all the argument constraints implied by [parameters] and
187+
/// [argumentTypes].
188+
void constrainArguments2(
189+
{InterfaceElement? genericClass,
190+
required List<FormalParameterElementMixin> parameters,
191+
required List<TypeImpl> argumentTypes,
192+
required AstNodeImpl? nodeForTesting}) {
193+
for (int i = 0; i < argumentTypes.length; i++) {
194+
// Try to pass each argument to each parameter, recording any type
195+
// parameter bounds that were implied by this assignment.
196+
constrainArgument(
197+
argumentTypes[i],
198+
parameters[i].type,
199+
parameters[i].name3!,
200+
genericClass: genericClass,
201+
nodeForTesting: nodeForTesting,
202+
);
203+
}
204+
}
205+
186206
/// Constrain a universal function type [fnType] used in a context
187207
/// [contextType].
188208
void constrainGenericFunctionInContext(

pkg/analyzer/test/src/dart/element/generic_inferrer_test.dart

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
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-
75
import 'package:_fe_analyzer_shared/src/type_inference/type_analyzer_operations.dart';
86
import 'package:analyzer/dart/ast/token.dart';
97
import 'package:analyzer/dart/element/type.dart';
@@ -200,21 +198,21 @@ class GenericFunctionInferenceTest extends AbstractTypeSystemTest {
200198
/// https://github.com/dart-lang/language/issues/1182#issuecomment-702272641
201199
void test_demoteType() {
202200
// <T>(T x) -> void
203-
var T = typeParameter('T');
204-
var rawType = functionTypeNone(
201+
var T = typeParameter2('T');
202+
var rawType = functionTypeNone2(
205203
typeFormals: [T],
206204
parameters: [
207-
requiredParameter(type: typeParameterTypeNone(T)),
205+
requiredParameter2(type: typeParameterTypeNone2(T)),
208206
],
209207
returnType: voidNone,
210208
);
211209

212-
var S = typeParameter('S');
213-
var S_and_int = typeParameterTypeNone(S, promotedBound: intNone);
210+
var S = typeParameter2('S');
211+
var S_and_int = typeParameterTypeNone2(S, promotedBound: intNone);
214212

215213
var inferredTypes = _inferCall(rawType, [S_and_int]);
216214
var inferredType = inferredTypes[0] as TypeParameterTypeImpl;
217-
expect(inferredType.element, S);
215+
expect(inferredType.element3, S);
218216
expect(inferredType.promotedBound, isNull);
219217
}
220218

@@ -636,10 +634,8 @@ class GenericFunctionInferenceTest extends AbstractTypeSystemTest {
636634
dataForTesting: null,
637635
nodeForTesting: null,
638636
);
639-
inferrer.constrainArguments(
640-
// TODO(paulberry): eliminate this cast by changing the type of
641-
// `FunctionTypeImpl.parameters` to `List<ParameterElementMixin>`.
642-
parameters: ft.parameters.cast(),
637+
inferrer.constrainArguments2(
638+
parameters: ft.formalParameters,
643639
argumentTypes: arguments,
644640
nodeForTesting: null);
645641
var typeArguments = inferrer.chooseFinalTypes();

0 commit comments

Comments
 (0)