Skip to content

Commit bb71ed4

Browse files
scheglovdart-scoped@luci-project-accounts.iam.gserviceaccount.com
authored andcommitted
AST. Resolve ReceiverMethodInvocation directly from ParsedX.
Resolve named receiver calls directly from `ParsedValueArguments` instead of lowering them through legacy `MethodInvocation` nodes before type analysis. Bind lexical receiver names first and keep the final selector parsed until the receiver type is known. Then create either a `ReceiverMethodInvocation` for direct methods, or a `CallInvocation` for callable properties. Represent type and extension qualifiers as `NamedReceiver`s so static calls use the same canonical V2 path. Carry the new shape through inference, null-aware flow handling, diagnostics, FFI validation, element lookup, V1 projections, serialization, and other AST consumers. Bump the analysis data version for the serialized receiver change. For explicit calls on function-typed receivers, the V1 `call` identifier now exposes the invocation's function type instead of `dynamic`. This was a pre-existing bug / inaccuracy that is now fixed. Bug: #63882 Change-Id: I60e0cfa1d23db9ae4d0e8b41b20b18b4a59bfe3b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/551900 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent 4e569c6 commit bb71ed4

44 files changed

Lines changed: 4536 additions & 1317 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎pkg/_fe_analyzer_shared/test/flow_analysis/why_not_promoted/data/nullable_expression_call_error.dart‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class C2 {
1616

1717
instance_method_invocation(C1 c) {
1818
if (c.bad == null) return;
19-
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C1.bad))*/
2019
c
21-
.bad
20+
.
21+
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C1.bad))*/ bad
2222
/*cfe.notPromoted(propertyNotPromotedForInherentReason(target: member:C1.bad))*/ ();
2323
}
2424

@@ -43,9 +43,9 @@ extension_invocation_method(C3 c) {
4343
if (c.ok == null) return;
4444
c.ok();
4545
if (c.bad == null) return;
46-
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C3.bad))*/
4746
c
48-
.bad
47+
.
48+
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C3.bad))*/ bad
4949
/*cfe.notPromoted(propertyNotPromotedForInherentReason(target: member:C3.bad))*/ ();
5050
}
5151

@@ -59,9 +59,9 @@ class C7 {
5959

6060
instance_getter_invocation(C6 c) {
6161
if (c.bad == null) return;
62-
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C6.bad))*/
6362
c
64-
.bad
63+
.
64+
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C6.bad))*/ bad
6565
/*cfe.notPromoted(propertyNotPromotedForInherentReason(target: member:C6.bad))*/ ();
6666
}
6767

@@ -86,9 +86,9 @@ extension_invocation_getter(C8 c) {
8686
if (c.ok == null) return;
8787
c.ok();
8888
if (c.bad == null) return;
89-
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C8.bad))*/
9089
c
91-
.bad
90+
.
91+
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C8.bad))*/ bad
9292
/*cfe.notPromoted(propertyNotPromotedForInherentReason(target: member:C8.bad))*/ ();
9393
}
9494

@@ -98,9 +98,9 @@ class C11 {
9898

9999
function_invocation(C11 c) {
100100
if (c.bad == null) return;
101-
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C11.bad))*/
102101
c
103-
.bad
102+
.
103+
/*analyzer.notPromoted(propertyNotPromotedForInherentReason(target: member:C11.bad))*/ bad
104104
/*cfe.notPromoted(propertyNotPromotedForInherentReason(target: member:C11.bad))*/ ();
105105
}
106106

‎pkg/analyzer/api.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2440,7 +2440,7 @@ package:analyzer/dart/ast/ast.dart:
24402440
receiver (getter: Expression)
24412441
ReceiverMethodInvocation (class extends Object implements NamedFunctionInvocation, abstract, final, experimental):
24422442
operator (getter: Token)
2443-
receiver (getter: Expression)
2443+
receiver (getter: NamedReceiver)
24442444
ReceiverPropertyAssignmentTarget (class extends Object implements PropertyAssignmentTarget, abstract, final, experimental):
24452445
operator (getter: Token)
24462446
receiver (getter: NamedReceiver)

‎pkg/analyzer/lib/src/dart/analysis/driver.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ testFineAfterLibraryAnalyzerHook;
112112
// TODO(scheglov): Clean up the list of implicitly analyzed files.
113113
class AnalysisDriver {
114114
/// The version of data format, should be incremented on every format change.
115-
static const int DATA_VERSION = 716;
115+
static const int DATA_VERSION = 717;
116116

117117
/// The number of exception contexts allowed to write. Once this field is
118118
/// zero, we stop writing any new exception contexts in this process.

‎pkg/analyzer/lib/src/dart/ast/ast.dart‎

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37605,6 +37605,8 @@ final class MethodInvocationImpl extends InvocationExpressionImpl
3760537605
};
3760637606
var methodNameType = switch (origin) {
3760737607
CascadeMethodInvocationImpl() => origin.staticInvokeType,
37608+
ReceiverMethodInvocationImpl(staticInvokeType: InvalidTypeImpl()) =>
37609+
origin.staticInvokeType,
3760837610
_ => switch (origin.resolution) {
3760937611
ExecutableInvocationResolutionImpl(:var element) => element.type,
3761037612
InvalidInvocationResolutionImpl(
@@ -38037,7 +38039,7 @@ final class MethodInvocationImpl extends InvocationExpressionImpl
3803738039
SimpleIdentifierImpl.v1Projection(token: importPrefix.name)
3803838040
..element = importPrefix.element,
3803938041
ReceiverMethodInvocationImpl(:var receiver) =>
38040-
V1Projection.toV1Expression(receiver),
38042+
V1Projection.toV1NamedReceiver(receiver),
3804138043
DotShorthandMethodInvocationImpl() => throw StateError(
3804238044
'DotShorthandMethodInvocation projects to DotShorthandInvocation.',
3804338045
),
@@ -41899,7 +41901,7 @@ sealed class ParsedAssignmentTargetImpl extends AssignmentTargetImpl
4189941901
WriteResolutionImpl? get write => null;
4190041902
}
4190141903

41902-
/// A parser-only expression whose names have not yet been assigned receiver roles.
41904+
/// A syntactic expression whose final semantic role has not yet been selected.
4190341905
@experimental
4190441906
@AnalyzerPublicApi(message: 'exported by lib/dart/ast/ast.dart')
4190541907
sealed class ParsedExpression implements Expression {}
@@ -42620,6 +42622,10 @@ final class ParsedUnqualifiedNameImpl extends ParsedExpressionImpl
4262042622
@override
4262142623
final Token name;
4262242624

42625+
/// Lexical binding retained when a call's qualifier stays in parsed form
42626+
/// until type-based member lookup.
42627+
ScopeLookupResult? scopeLookupResult;
42628+
4262342629
@generated
4262442630
ParsedUnqualifiedNameImpl({required this.name});
4262542631

@@ -42763,6 +42769,19 @@ final class ParsedValueArgumentsImpl extends ParsedExpressionImpl
4276342769
return argumentList.endToken;
4276442770
}
4276542771

42772+
/// The final selector and optional invocation type arguments of a named call.
42773+
@DoNotGenerate(reason: 'Groups nested invocation syntax without lowering it')
42774+
({ParsedNameAccessImpl selector, TypeArgumentListImpl? typeArguments})?
42775+
get namedInvocationParts => switch (operand) {
42776+
ParsedNameAccessImpl selector => (selector: selector, typeArguments: null),
42777+
ParsedTypeArgumentsImpl(
42778+
operand: ParsedNameAccessImpl selector,
42779+
:var typeArguments,
42780+
) =>
42781+
(selector: selector, typeArguments: typeArguments),
42782+
_ => null,
42783+
};
42784+
4276642785
@generated
4276742786
@override
4276842787
ParsedExpressionImpl get operand => _operand;
@@ -42834,10 +42853,10 @@ final class ParsedValueArgumentsImpl extends ParsedExpressionImpl
4283442853
super.replaceChild(oldNode, newNode);
4283542854
}
4283642855

42837-
@DoNotGenerate(reason: 'Parser-only nodes are lowered before type inference')
42856+
@generated
4283842857
@override
4283942858
void resolveExpression(ResolverVisitor resolver, TypeImpl contextType) {
42840-
throw StateError('Parsed expressions must be lowered before resolution.');
42859+
resolver.visitParsedValueArguments(this, contextType: contextType);
4284142860
}
4284242861

4284342862
@generated
@@ -46698,20 +46717,16 @@ final class ReceiverIndexExpressionImpl extends IndexExpression2Impl
4669846717
}
4669946718
}
4670046719

46701-
/// A direct method invocation on an explicitly written expression receiver.
46702-
///
46703-
/// This migration slice supports receivers whose value-producing role is
46704-
/// structurally unambiguous. Other receiver forms remain on their existing AST
46705-
/// shapes until named receivers and parser-only chains are implemented.
46720+
/// A direct method invocation on an explicitly written receiver or qualifier.
4670646721
@experimental
4670746722
@AnalyzerPublicApi(message: 'exported by lib/dart/ast/ast.dart')
4670846723
abstract final class ReceiverMethodInvocation
4670946724
implements NamedFunctionInvocation {
4671046725
/// The operator separating the receiver from the method name.
4671146726
Token get operator;
4671246727

46713-
/// The expression whose value receives the method invocation.
46714-
Expression get receiver;
46728+
/// The value receiver or static namespace selecting the method.
46729+
NamedReceiver get receiver;
4671546730
}
4671646731

4671746732
@GenerateNodeImpl(
@@ -46727,7 +46742,7 @@ abstract final class ReceiverMethodInvocation
4672746742
final class ReceiverMethodInvocationImpl extends NamedFunctionInvocationImpl
4672846743
implements ReceiverMethodInvocation {
4672946744
@generated
46730-
ExpressionImpl _receiver;
46745+
NamedReceiverImpl _receiver;
4673146746

4673246747
@generated
4673346748
@override
@@ -46737,7 +46752,7 @@ final class ReceiverMethodInvocationImpl extends NamedFunctionInvocationImpl
4673746752

4673846753
@generated
4673946754
ReceiverMethodInvocationImpl({
46740-
required ExpressionImpl receiver,
46755+
required NamedReceiverImpl receiver,
4674146756
required this.operator,
4674246757
required super.name,
4674346758
required super.typeArguments,
@@ -46764,10 +46779,10 @@ final class ReceiverMethodInvocationImpl extends NamedFunctionInvocationImpl
4676446779

4676546780
@generated
4676646781
@override
46767-
ExpressionImpl get receiver => _receiver;
46782+
NamedReceiverImpl get receiver => _receiver;
4676846783

4676946784
@DoNotGenerate(reason: 'Keeps the cached V1 projection synchronized')
46770-
set receiver(ExpressionImpl receiver) {
46785+
set receiver(NamedReceiverImpl receiver) {
4677146786
_receiver = _becomeParentOf2(receiver);
4677246787
_methodInvocation?._attachV1Children();
4677346788
}
@@ -46831,7 +46846,7 @@ final class ReceiverMethodInvocationImpl extends NamedFunctionInvocationImpl
4683146846
@override
4683246847
void replaceChild(AstNodeImpl oldNode, AstNodeImpl newNode) {
4683346848
if (identical(receiver, oldNode)) {
46834-
receiver = newNode as ExpressionImpl;
46849+
receiver = newNode as NamedReceiverImpl;
4683546850
return;
4683646851
}
4683746852
if (identical(typeArguments, oldNode)) {
@@ -46876,7 +46891,7 @@ final class ReceiverMethodInvocationImpl extends NamedFunctionInvocationImpl
4687646891
@experimental
4687746892
void visitChildrenWithHooks(
4687846893
AstVisitor2 visitor, {
46879-
void Function(ExpressionImpl)? visitReceiver,
46894+
void Function(NamedReceiverImpl)? visitReceiver,
4688046895
void Function(TypeArgumentListImpl)? visitTypeArguments,
4688146896
void Function(ArgumentListImpl)? visitArgumentList,
4688246897
}) {

‎pkg/analyzer/lib/src/dart/ast/element_locator.dart‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,10 @@ class _ElementMapperV2 extends UnifyingAstVisitor2<Element> {
586586

587587
@override
588588
Element? visitReceiverMethodInvocation(ReceiverMethodInvocation node) {
589+
if (node.receiver case NameExpression receiver
590+
when node.resolution is FunctionCallInvocationResolution) {
591+
return receiver.resolution?.elementOrRecovery;
592+
}
589593
return _visitNamedFunctionInvocation(node);
590594
}
591595

0 commit comments

Comments
 (0)