Rework `InvocationInferrer.rawType`.
Changed from a non-final field to a parameter, to avoid confusion when
the value changes.
Change-Id: If7190ed36d93b903f61a3ea41bfa438bc287b734
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240646
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/annotation_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/annotation_resolver.dart
index f43c056..e50459e 100644
--- a/pkg/analyzer/lib/src/dart/resolver/annotation_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/annotation_resolver.dart
@@ -115,11 +115,10 @@
resolver: _resolver,
node: node,
argumentList: argumentList,
- rawType: null,
contextType: null,
whyNotPromotedList: whyNotPromotedList,
constructorName: constructorName)
- .resolveInvocation();
+ .resolveInvocation(rawType: null);
return;
}
@@ -133,11 +132,10 @@
resolver: _resolver,
node: node,
argumentList: argumentList,
- rawType: constructorRawType,
contextType: null,
whyNotPromotedList: whyNotPromotedList,
constructorName: constructorName)
- .resolveInvocation();
+ .resolveInvocation(rawType: constructorRawType);
}
void _extensionGetter(
@@ -407,11 +405,10 @@
resolver: _resolver,
node: node,
argumentList: arguments,
- rawType: null,
contextType: null,
whyNotPromotedList: whyNotPromotedList,
constructorName: null)
- .resolveInvocation();
+ .resolveInvocation(rawType: null);
}
}
}
diff --git a/pkg/analyzer/lib/src/dart/resolver/function_expression_invocation_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/function_expression_invocation_resolver.dart
index 03d4601..26bb256 100644
--- a/pkg/analyzer/lib/src/dart/resolver/function_expression_invocation_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/function_expression_invocation_resolver.dart
@@ -119,10 +119,9 @@
resolver: _resolver,
node: node,
argumentList: node.argumentList,
- rawType: rawType,
whyNotPromotedList: whyNotPromotedList,
contextType: contextType,
- ).resolveInvocation();
+ ).resolveInvocation(rawType: rawType);
_inferenceHelper.recordStaticType(node, returnType,
contextType: contextType);
@@ -209,10 +208,9 @@
resolver: _resolver,
node: node,
argumentList: node.argumentList,
- rawType: null,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList)
- .resolveInvocation();
+ .resolveInvocation(rawType: null);
node.staticInvokeType = DynamicTypeImpl.instance;
node.staticType = type;
}
diff --git a/pkg/analyzer/lib/src/dart/resolver/instance_creation_expression_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/instance_creation_expression_resolver.dart
index 7445573..71472fa 100644
--- a/pkg/analyzer/lib/src/dart/resolver/instance_creation_expression_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/instance_creation_expression_resolver.dart
@@ -66,10 +66,9 @@
resolver: _resolver,
node: node,
argumentList: node.argumentList,
- rawType: elementToInfer?.asType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList)
- .resolveInvocation();
+ .resolveInvocation(rawType: elementToInfer?.asType);
_resolver.inferenceHelper.recordStaticType(
node, node.constructorName.type.type!,
contextType: contextType);
diff --git a/pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart b/pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart
index 495866a..ee320b5 100644
--- a/pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart
@@ -174,10 +174,9 @@
resolver: _resolver,
node: node,
argumentList: node.argumentList,
- rawType: rawType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList,
- ).resolveInvocation();
+ ).resolveInvocation(rawType: rawType);
recordStaticType(node, returnType, contextType: contextType);
}
diff --git a/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart b/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
index fe15873..2c82679 100644
--- a/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
@@ -61,7 +61,6 @@
{required ResolverVisitor resolver,
required AnnotationImpl node,
required ArgumentListImpl argumentList,
- required FunctionType? rawType,
required DartType? contextType,
required List<WhyNotPromotedGetter> whyNotPromotedList,
required this.constructorName})
@@ -69,7 +68,6 @@
resolver: resolver,
node: node,
argumentList: argumentList,
- rawType: rawType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList);
@@ -113,14 +111,12 @@
{required ResolverVisitor resolver,
required Node node,
required ArgumentListImpl argumentList,
- required FunctionType? rawType,
required DartType? contextType,
required List<WhyNotPromotedGetter> whyNotPromotedList})
: super(
resolver: resolver,
node: node,
argumentList: argumentList,
- rawType: rawType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList);
@@ -138,9 +134,8 @@
CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS_METHOD;
@override
- DartType resolveInvocation() {
+ DartType resolveInvocation({required FunctionType? rawType}) {
var typeArgumentList = _typeArguments;
- var rawType = this.rawType;
List<DartType>? typeArgumentTypes;
GenericInferrer? inferrer;
@@ -202,7 +197,7 @@
} else if (rawType == null || rawType.typeFormals.isEmpty) {
typeArgumentTypes = const <DartType>[];
} else {
- this.rawType = rawType = getFreshTypeParameters(rawType.typeFormals)
+ rawType = getFreshTypeParameters(rawType.typeFormals)
.applyToFunctionType(rawType);
inferrer = resolver.typeSystem.setupGenericTypeInference(
@@ -233,7 +228,8 @@
resolver.typeSystem,
deferredClosures,
rawType?.typeFormals.toSet() ?? const {},
- _computeUndeferredParamInfo(parameterMap, deferredClosures))
+ _computeUndeferredParamInfo(
+ rawType, parameterMap, deferredClosures))
.planReconciliationStages()) {
if (inferrer != null && !isFirstStage) {
substitution = Substitution.fromPairs(
@@ -273,6 +269,7 @@
/// Computes a list of [_ParamInfo] objects corresponding to the invocation
/// parameters that were *not* deferred.
List<_ParamInfo> _computeUndeferredParamInfo(
+ FunctionType? rawType,
Map<Object, ParameterElement> parameterMap,
List<_DeferredParamInfo> deferredClosures) {
if (rawType == null) return const [];
@@ -315,14 +312,12 @@
{required ResolverVisitor resolver,
required FunctionExpressionInvocationImpl node,
required ArgumentListImpl argumentList,
- required FunctionType? rawType,
required DartType? contextType,
required List<WhyNotPromotedGetter> whyNotPromotedList})
: super._(
resolver: resolver,
node: node,
argumentList: argumentList,
- rawType: rawType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList);
@@ -338,14 +333,12 @@
{required ResolverVisitor resolver,
required InstanceCreationExpressionImpl node,
required ArgumentListImpl argumentList,
- required FunctionType? rawType,
required DartType? contextType,
required List<WhyNotPromotedGetter> whyNotPromotedList})
: super._(
resolver: resolver,
node: node,
argumentList: argumentList,
- rawType: rawType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList);
@@ -397,14 +390,12 @@
{required ResolverVisitor resolver,
required Node node,
required ArgumentListImpl argumentList,
- required FunctionType? rawType,
required DartType? contextType,
required List<WhyNotPromotedGetter> whyNotPromotedList})
: super._(
resolver: resolver,
node: node,
argumentList: argumentList,
- rawType: rawType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList);
@@ -432,18 +423,15 @@
final ResolverVisitor resolver;
final Node node;
final ArgumentListImpl argumentList;
- FunctionType? rawType;
final DartType? contextType;
final List<WhyNotPromotedGetter> whyNotPromotedList;
/// Prepares to perform type inference on an invocation expression of type
- /// [Node]. [rawType] should be the type of the function the invocation is
- /// resolved to (with type arguments not applied yet).
+ /// [Node].
InvocationInferrer(
{required this.resolver,
required this.node,
required this.argumentList,
- required this.rawType,
required this.contextType,
required this.whyNotPromotedList});
@@ -451,8 +439,10 @@
/// `identical` (which needs special flow analysis treatment).
bool get _isIdentical => false;
- /// Performs type inference on the invocation expression.
- void resolveInvocation() {
+ /// Performs type inference on the invocation expression. [rawType] should be
+ /// the type of the function the invocation is resolved to (with type
+ /// arguments not applied yet).
+ void resolveInvocation({required FunctionType? rawType}) {
var deferredClosures = _visitArguments(
parameterMap: _computeParameterMap(rawType?.parameters ?? const []));
if (deferredClosures != null) {
@@ -591,14 +581,12 @@
{required ResolverVisitor resolver,
required MethodInvocationImpl node,
required ArgumentListImpl argumentList,
- required FunctionType? rawType,
required DartType? contextType,
required List<WhyNotPromotedGetter> whyNotPromotedList})
: super._(
resolver: resolver,
node: node,
argumentList: argumentList,
- rawType: rawType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList);
diff --git a/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart b/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart
index 081bb5d..e7d3b26 100644
--- a/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart
+++ b/pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart
@@ -332,10 +332,9 @@
resolver: _resolver,
node: node,
argumentList: node.argumentList,
- rawType: rawType is FunctionType ? rawType : null,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList)
- .resolveInvocation();
+ .resolveInvocation(rawType: rawType is FunctionType ? rawType : null);
_inferenceHelper.recordStaticType(node, staticStaticType,
contextType: contextType);
}
@@ -478,10 +477,9 @@
resolver: _resolver,
node: node,
argumentList: node.argumentList,
- rawType: rawType,
whyNotPromotedList: whyNotPromotedList,
contextType: contextType)
- .resolveInvocation();
+ .resolveInvocation(rawType: rawType);
}
void _resolveReceiverFunctionBounded(
@@ -553,10 +551,9 @@
resolver: _resolver,
node: node,
argumentList: node.argumentList,
- rawType: null,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList)
- .resolveInvocation();
+ .resolveInvocation(rawType: null);
_resolver.errorReporter.reportErrorForNode(
HintCode.RECEIVER_OF_TYPE_NEVER,
@@ -574,10 +571,9 @@
resolver: _resolver,
node: node,
argumentList: node.argumentList,
- rawType: null,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList)
- .resolveInvocation();
+ .resolveInvocation(rawType: null);
return;
}
}
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index b757ae5..0d4d071 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -1545,6 +1545,9 @@
resolver: this,
node: node,
argumentList: node.argumentList,
+ contextType: null,
+ whyNotPromotedList: whyNotPromotedList)
+ .resolveInvocation(
rawType: receiverContextType == null
? null
: FunctionTypeImpl(
@@ -1554,10 +1557,7 @@
null, receiverContextType, ParameterKind.REQUIRED)
],
returnType: DynamicTypeImpl.instance,
- nullabilitySuffix: NullabilitySuffix.none),
- contextType: null,
- whyNotPromotedList: whyNotPromotedList)
- .resolveInvocation();
+ nullabilitySuffix: NullabilitySuffix.none));
extensionResolver.resolveOverride(node, whyNotPromotedList);
}
@@ -2170,10 +2170,9 @@
resolver: this,
node: node,
argumentList: node.argumentList,
- rawType: node.staticElement?.type,
contextType: null,
whyNotPromotedList: whyNotPromotedList)
- .resolveInvocation();
+ .resolveInvocation(rawType: node.staticElement?.type);
checkForArgumentTypesNotAssignableInList(
node.argumentList, whyNotPromotedList);
}
@@ -2280,10 +2279,9 @@
resolver: this,
node: node,
argumentList: node.argumentList,
- rawType: node.staticElement?.type,
contextType: null,
whyNotPromotedList: whyNotPromotedList)
- .resolveInvocation();
+ .resolveInvocation(rawType: node.staticElement?.type);
checkForArgumentTypesNotAssignableInList(
node.argumentList, whyNotPromotedList);
}