Skip to content

Commit

Permalink
Rework InvocationInferrer.rawType.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Samuel Rawlins <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
  • Loading branch information
stereotype441 authored and Commit Bot committed Apr 12, 2022
1 parent 6780963 commit 02fc734
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 52 deletions.
9 changes: 3 additions & 6 deletions pkg/analyzer/lib/src/dart/resolver/annotation_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,10 @@ class AnnotationResolver {
resolver: _resolver,
node: node,
argumentList: argumentList,
rawType: null,
contextType: null,
whyNotPromotedList: whyNotPromotedList,
constructorName: constructorName)
.resolveInvocation();
.resolveInvocation(rawType: null);
return;
}

Expand All @@ -133,11 +132,10 @@ class AnnotationResolver {
resolver: _resolver,
node: node,
argumentList: argumentList,
rawType: constructorRawType,
contextType: null,
whyNotPromotedList: whyNotPromotedList,
constructorName: constructorName)
.resolveInvocation();
.resolveInvocation(rawType: constructorRawType);
}

void _extensionGetter(
Expand Down Expand Up @@ -407,11 +405,10 @@ class AnnotationResolver {
resolver: _resolver,
node: node,
argumentList: arguments,
rawType: null,
contextType: null,
whyNotPromotedList: whyNotPromotedList,
constructorName: null)
.resolveInvocation();
.resolveInvocation(rawType: null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,9 @@ class FunctionExpressionInvocationResolver {
resolver: _resolver,
node: node,
argumentList: node.argumentList,
rawType: rawType,
whyNotPromotedList: whyNotPromotedList,
contextType: contextType,
).resolveInvocation();
).resolveInvocation(rawType: rawType);

_inferenceHelper.recordStaticType(node, returnType,
contextType: contextType);
Expand Down Expand Up @@ -209,10 +208,9 @@ class FunctionExpressionInvocationResolver {
resolver: _resolver,
node: node,
argumentList: node.argumentList,
rawType: null,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList)
.resolveInvocation();
.resolveInvocation(rawType: null);
node.staticInvokeType = DynamicTypeImpl.instance;
node.staticType = type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ class InstanceCreationExpressionResolver {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,9 @@ class InvocationInferenceHelper {
resolver: _resolver,
node: node,
argumentList: node.argumentList,
rawType: rawType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList,
).resolveInvocation();
).resolveInvocation(rawType: rawType);

recordStaticType(node, returnType, contextType: contextType);
}
Expand Down
32 changes: 10 additions & 22 deletions pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ class AnnotationInferrer extends FullInvocationInferrer<AnnotationImpl> {
{required ResolverVisitor resolver,
required AnnotationImpl node,
required ArgumentListImpl argumentList,
required FunctionType? rawType,
required DartType? contextType,
required List<WhyNotPromotedGetter> whyNotPromotedList,
required this.constructorName})
: super._(
resolver: resolver,
node: node,
argumentList: argumentList,
rawType: rawType,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList);

Expand Down Expand Up @@ -113,14 +111,12 @@ abstract class FullInvocationInferrer<Node extends AstNodeImpl>
{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);

Expand All @@ -138,9 +134,8 @@ abstract class FullInvocationInferrer<Node extends AstNodeImpl>
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;
Expand Down Expand Up @@ -202,7 +197,7 @@ abstract class FullInvocationInferrer<Node extends AstNodeImpl>
} 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(
Expand Down Expand Up @@ -233,7 +228,8 @@ abstract class FullInvocationInferrer<Node extends AstNodeImpl>
resolver.typeSystem,
deferredClosures,
rawType?.typeFormals.toSet() ?? const {},
_computeUndeferredParamInfo(parameterMap, deferredClosures))
_computeUndeferredParamInfo(
rawType, parameterMap, deferredClosures))
.planReconciliationStages()) {
if (inferrer != null && !isFirstStage) {
substitution = Substitution.fromPairs(
Expand Down Expand Up @@ -273,6 +269,7 @@ abstract class FullInvocationInferrer<Node extends AstNodeImpl>
/// 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 [];
Expand Down Expand Up @@ -315,14 +312,12 @@ class FunctionExpressionInvocationInferrer
{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);

Expand All @@ -338,14 +333,12 @@ class InstanceCreationInferrer
{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);

Expand Down Expand Up @@ -397,14 +390,12 @@ abstract class InvocationExpressionInferrer<
{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);

Expand Down Expand Up @@ -432,27 +423,26 @@ class InvocationInferrer<Node extends AstNodeImpl> {
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});

/// Determines whether [node] is an invocation of the core function
/// `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) {
Expand Down Expand Up @@ -591,14 +581,12 @@ class MethodInvocationInferrer
{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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,9 @@ class MethodInvocationResolver {
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);
}
Expand Down Expand Up @@ -478,10 +477,9 @@ class MethodInvocationResolver {
resolver: _resolver,
node: node,
argumentList: node.argumentList,
rawType: rawType,
whyNotPromotedList: whyNotPromotedList,
contextType: contextType)
.resolveInvocation();
.resolveInvocation(rawType: rawType);
}

void _resolveReceiverFunctionBounded(
Expand Down Expand Up @@ -553,10 +551,9 @@ class MethodInvocationResolver {
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,
Expand All @@ -574,10 +571,9 @@ class MethodInvocationResolver {
resolver: _resolver,
node: node,
argumentList: node.argumentList,
rawType: null,
contextType: contextType,
whyNotPromotedList: whyNotPromotedList)
.resolveInvocation();
.resolveInvocation(rawType: null);
return;
}
}
Expand Down
14 changes: 6 additions & 8 deletions pkg/analyzer/lib/src/generated/resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,9 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
resolver: this,
node: node,
argumentList: node.argumentList,
contextType: null,
whyNotPromotedList: whyNotPromotedList)
.resolveInvocation(
rawType: receiverContextType == null
? null
: FunctionTypeImpl(
Expand All @@ -1554,10 +1557,7 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
null, receiverContextType, ParameterKind.REQUIRED)
],
returnType: DynamicTypeImpl.instance,
nullabilitySuffix: NullabilitySuffix.none),
contextType: null,
whyNotPromotedList: whyNotPromotedList)
.resolveInvocation();
nullabilitySuffix: NullabilitySuffix.none));

extensionResolver.resolveOverride(node, whyNotPromotedList);
}
Expand Down Expand Up @@ -2170,10 +2170,9 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
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);
}
Expand Down Expand Up @@ -2280,10 +2279,9 @@ class ResolverVisitor extends ThrowingAstVisitor<void>
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);
}
Expand Down

0 comments on commit 02fc734

Please sign in to comment.