Skip to content

Commit 0bf9183

Browse files
kallentuCommit Queue
authored and
Commit Queue
committed
[analyzer] Dot shorthands: Refactoring MethodInvocationResolver to handle dot shorthands.
This is the base preliminary work for resolving dot shorthand invocations. I'll be calling `resolveDotShorthand` from the `Resolver` in a future CL. Dot shorthand invocation resolution is very similar to normal MethodInvocation resolution, with a few exceptions (like no `target` expression), so it made sense to re-use the logic we had in the `MethodInvocationResolver`. I refactored `_rewriteAsFunctionExpressionInvocation` heavily to support both dot shorthands and method invocations, which involved pulling out all of the members into parameters. Most `_report<some error>` methods were refactored to support dot shorthands as well. Half of them called `_setInvalidTypeResolution` and that ended up just being invoked at the call site rather than in the report helper itself. Dot shorthands has a very basic `DotShorthandInvocationInferrer` in this CL. None of the overrides for a `MethodInvocationInferrer` seemed to apply since we don't have a target. No tests yet. Tests will be added once I make the next CL that calls this `resolveDotShorthand` entry point. Bug: #59835 Change-Id: I8ebeb772c30c88b85ae68d805e062accb1d6d17d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421560 Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]>
1 parent 4ce0cf3 commit 0bf9183

File tree

3 files changed

+340
-73
lines changed

3 files changed

+340
-73
lines changed

pkg/analyzer/lib/src/dart/resolver/invocation_inference_helper.dart

+23-6
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,35 @@ class InvocationInferenceHelper {
155155
return tearOffType;
156156
}
157157

158+
/// Finish resolution of the [DotShorthandInvocation].
159+
///
160+
/// We have already found the invoked [ExecutableElement2], and the [rawType]
161+
/// is its not yet instantiated type. Here we perform downwards inference,
162+
/// resolution of arguments, and upwards inference.
163+
void resolveDotShorthandInvocation({
164+
required DotShorthandInvocationImpl node,
165+
required FunctionTypeImpl rawType,
166+
required List<WhyNotPromotedGetter> whyNotPromotedArguments,
167+
required TypeImpl contextType,
168+
}) {
169+
var returnType = DotShorthandInvocationInferrer(
170+
resolver: _resolver,
171+
node: node,
172+
argumentList: node.argumentList,
173+
contextType: contextType,
174+
whyNotPromotedArguments: whyNotPromotedArguments,
175+
).resolveInvocation(rawType: rawType);
176+
node.recordStaticType(returnType, resolver: _resolver);
177+
}
178+
158179
/// Finish resolution of the [MethodInvocation].
159180
///
160181
/// We have already found the invoked [ExecutableElement2], and the [rawType]
161182
/// is its not yet instantiated type. Here we perform downwards inference,
162183
/// resolution of arguments, and upwards inference.
163184
void resolveMethodInvocation({
164185
required MethodInvocationImpl node,
165-
required FunctionType rawType,
186+
required FunctionTypeImpl rawType,
166187
required List<WhyNotPromotedGetter> whyNotPromotedArguments,
167188
required TypeImpl contextType,
168189
}) {
@@ -172,11 +193,7 @@ class InvocationInferenceHelper {
172193
argumentList: node.argumentList,
173194
contextType: contextType,
174195
whyNotPromotedArguments: whyNotPromotedArguments,
175-
).resolveInvocation(
176-
// TODO(paulberry): eliminate this cast by changing the type of
177-
// `rawType`.
178-
rawType: rawType as FunctionTypeImpl);
179-
196+
).resolveInvocation(rawType: rawType);
180197
node.recordStaticType(returnType, resolver: _resolver);
181198
}
182199
}

pkg/analyzer/lib/src/dart/resolver/invocation_inferrer.dart

+13
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ class AugmentedInvocationInferrer
131131
CompileTimeErrorCode.WRONG_NUMBER_OF_TYPE_ARGUMENTS;
132132
}
133133

134+
/// Specialization of [InvocationInferrer] for performing type inference on AST
135+
/// nodes of type [DotShorthandInvocation].
136+
class DotShorthandInvocationInferrer
137+
extends InvocationExpressionInferrer<DotShorthandInvocationImpl> {
138+
DotShorthandInvocationInferrer(
139+
{required super.resolver,
140+
required super.node,
141+
required super.argumentList,
142+
required super.contextType,
143+
required super.whyNotPromotedArguments})
144+
: super._();
145+
}
146+
134147
/// Specialization of [InvocationInferrer] for performing type inference on AST
135148
/// nodes that require full downward and upward inference.
136149
abstract class FullInvocationInferrer<Node extends AstNodeImpl>

0 commit comments

Comments
 (0)