Push logic for constraining argument types into `InvocationInferrer._visitArguments`.
This allows us to avoid some redundant computation (we don't have to
match up arguments to the corresponding parameters twice). It also
paves the way for supporting improved type inference of `fold`
(https://github.com/dart-lang/language/issues/731) because it will
allow us to resolve some arguments (gathering more constraints), then
compute a new set of inferred types, then resolve more arguments, and
so on, rather than forcing us to do all the constraint gathering at
the end.
Change-Id: I67d8b8228390ced14281145a4614f66c8e3c7e73
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238622
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
diff --git a/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart b/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
index a645d81..6867d3b 100644
--- a/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
@@ -171,26 +171,10 @@
contextType: contextType,
whyNotPromotedList: whyNotPromotedList,
identicalInfo: identicalInfo,
- substitution: substitution);
+ substitution: substitution,
+ inferrer: inferrer);
if (inferrer != null) {
- // Get the parameters that correspond to the uninstantiated generic.
- List<ParameterElement?> rawParameters =
- ResolverVisitor.resolveArgumentsToParameters(
- argumentList: argumentList,
- parameters: rawType!.parameters,
- );
-
- List<ParameterElement> params = <ParameterElement>[];
- List<DartType> argTypes = <DartType>[];
- for (int i = 0, length = rawParameters.length; i < length; i++) {
- ParameterElement? parameter = rawParameters[i];
- if (parameter != null) {
- params.add(parameter);
- argTypes.add(argumentList.arguments[i].typeOrThrow);
- }
- }
- inferrer.constrainArguments(parameters: params, argumentTypes: argTypes);
typeArgumentTypes = inferrer.upwardsInfer();
}
FunctionType? invokeType = typeArgumentTypes != null
@@ -398,7 +382,8 @@
required DartType? contextType,
required List<WhyNotPromotedGetter> whyNotPromotedList,
List<EqualityInfo<PromotableElement, DartType>?>? identicalInfo,
- Substitution? substitution}) {
+ Substitution? substitution,
+ GenericInferrer? inferrer}) {
assert(whyNotPromotedList.isEmpty);
var parameters = rawType?.parameters;
var namedParameters = <String, ParameterElement>{};
@@ -445,6 +430,10 @@
?.add(flow.equalityOperand_end(argument, argument.typeOrThrow));
whyNotPromotedList.add(flow.whyNotPromoted(argument));
}
+ if (parameter != null) {
+ inferrer?.constrainArgument(
+ argument.typeOrThrow, parameter.type, parameter.name);
+ }
}
}