Skip to content

Commit 638f015

Browse files
kallentuCommit Queue
authored andcommitted
[analyzer] Dot Shorthands: Store DotShorthandPropertyAccess in summary.
Testing - Language tests stop crashing, some passing (the failures are from other unimplemented things). Added a unit test for a top level dot shorthand. Bug: #59835 Change-Id: I885cfc5c33b0b206aeae73438c765f73f4c9175f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422845 Commit-Queue: Kallen Tu <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
1 parent 7cb48f8 commit 638f015

File tree

6 files changed

+125
-1
lines changed

6 files changed

+125
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ import 'package:meta/meta.dart';
100100
// TODO(scheglov): Clean up the list of implicitly analyzed files.
101101
class AnalysisDriver {
102102
/// The version of data format, should be incremented on every format change.
103-
static const int DATA_VERSION = 452;
103+
static const int DATA_VERSION = 453;
104104

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

pkg/analyzer/lib/src/summary2/ast_binary_reader.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ class AstBinaryReader {
6565
return _readDeclaredIdentifier();
6666
case Tag.DefaultFormalParameter:
6767
return _readDefaultFormalParameter();
68+
case Tag.DotShorthandPropertyAccess:
69+
return _readDotShorthandPropertyAccess();
6870
case Tag.DottedName:
6971
return _readDottedName();
7072
case Tag.DoubleLiteral:
@@ -467,6 +469,16 @@ class AstBinaryReader {
467469
return node;
468470
}
469471

472+
DotShorthandPropertyAccess _readDotShorthandPropertyAccess() {
473+
var propertyName = readNode() as SimpleIdentifierImpl;
474+
var node = DotShorthandPropertyAccessImpl(
475+
period: Tokens.period(),
476+
propertyName: propertyName,
477+
);
478+
_readExpressionResolution(node);
479+
return node;
480+
}
481+
470482
DottedName _readDottedName() {
471483
var components = _readNodeList<SimpleIdentifierImpl>();
472484
return DottedNameImpl(

pkg/analyzer/lib/src/summary2/ast_binary_tag.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class Tag {
4747
static const int DeclaredIdentifier = 90;
4848
static const int DefaultFormalParameter = 8;
4949
static const int DottedName = 47;
50+
static const int DotShorthandPropertyAccess = 113;
5051
static const int DoubleLiteral = 9;
5152
static const int ExtensionOverride = 87;
5253
static const int FieldFormalParameter = 16;

pkg/analyzer/lib/src/summary2/ast_binary_writer.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ class AstBinaryWriter extends ThrowingAstVisitor<void> {
228228
_writeOptionalNode(defaultValue);
229229
}
230230

231+
@override
232+
void visitDotShorthandPropertyAccess(DotShorthandPropertyAccess node) {
233+
_writeByte(Tag.DotShorthandPropertyAccess);
234+
_writeNode(node.propertyName);
235+
_storeExpression(node);
236+
}
237+
231238
@override
232239
void visitDottedName(DottedName node) {
233240
_writeByte(Tag.DottedName);

pkg/analyzer/lib/src/summary2/informative_data.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,6 +2314,12 @@ abstract class _OffsetsAstVisitor extends RecursiveAstVisitor<void> {
23142314
node.name?.accept(this);
23152315
}
23162316

2317+
@override
2318+
void visitDotShorthandPropertyAccess(DotShorthandPropertyAccess node) {
2319+
_tokenOrNull(node.period);
2320+
node.propertyName.accept(this);
2321+
}
2322+
23172323
@override
23182324
void visitDoubleLiteral(DoubleLiteral node) {
23192325
_tokenOrNull(node.literal);

pkg/analyzer/test/src/summary/elements/const_test.dart

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,104 @@ library
591591
''');
592592
}
593593

594+
test_const_dotShorthand_property() async {
595+
var library = await buildLibrary(r'''
596+
class A {
597+
static const A a = A();
598+
const A();
599+
}
600+
601+
const A a = .a;
602+
''');
603+
checkElementText(library, r'''
604+
library
605+
reference: <testLibrary>
606+
fragments
607+
<testLibraryFragment>
608+
element: <testLibrary>
609+
classes
610+
class A @6
611+
reference: <testLibraryFragment>::@class::A
612+
element: <testLibrary>::@class::A
613+
fields
614+
hasInitializer a @27
615+
reference: <testLibraryFragment>::@class::A::@field::a
616+
element: <testLibraryFragment>::@class::A::@field::a#element
617+
initializer: expression_0
618+
InstanceCreationExpression
619+
constructorName: ConstructorName
620+
type: NamedType
621+
name: A @31
622+
element2: <testLibrary>::@class::A
623+
type: A
624+
element: <testLibraryFragment>::@class::A::@constructor::new#element
625+
argumentList: ArgumentList
626+
leftParenthesis: ( @32
627+
rightParenthesis: ) @33
628+
staticType: A
629+
getter2: <testLibraryFragment>::@class::A::@getter::a
630+
constructors
631+
const new
632+
reference: <testLibraryFragment>::@class::A::@constructor::new
633+
element: <testLibraryFragment>::@class::A::@constructor::new#element
634+
typeName: A
635+
typeNameOffset: 44
636+
getters
637+
synthetic get a
638+
reference: <testLibraryFragment>::@class::A::@getter::a
639+
element: <testLibraryFragment>::@class::A::@getter::a#element
640+
topLevelVariables
641+
hasInitializer a @60
642+
reference: <testLibraryFragment>::@topLevelVariable::a
643+
element: <testLibrary>::@topLevelVariable::a
644+
initializer: expression_1
645+
DotShorthandPropertyAccess
646+
period: . @64
647+
propertyName: SimpleIdentifier
648+
token: a @65
649+
element: <testLibraryFragment>::@class::A::@getter::a#element
650+
staticType: A
651+
staticType: A
652+
getter2: <testLibraryFragment>::@getter::a
653+
getters
654+
synthetic get a
655+
reference: <testLibraryFragment>::@getter::a
656+
element: <testLibraryFragment>::@getter::a#element
657+
classes
658+
class A
659+
reference: <testLibrary>::@class::A
660+
firstFragment: <testLibraryFragment>::@class::A
661+
fields
662+
static const hasInitializer a
663+
firstFragment: <testLibraryFragment>::@class::A::@field::a
664+
type: A
665+
constantInitializer
666+
fragment: <testLibraryFragment>::@class::A::@field::a
667+
expression: expression_0
668+
getter: <testLibraryFragment>::@class::A::@getter::a#element
669+
constructors
670+
const new
671+
firstFragment: <testLibraryFragment>::@class::A::@constructor::new
672+
getters
673+
synthetic static get a
674+
firstFragment: <testLibraryFragment>::@class::A::@getter::a
675+
returnType: A
676+
topLevelVariables
677+
const hasInitializer a
678+
reference: <testLibrary>::@topLevelVariable::a
679+
firstFragment: <testLibraryFragment>::@topLevelVariable::a
680+
type: A
681+
constantInitializer
682+
fragment: <testLibraryFragment>::@topLevelVariable::a
683+
expression: expression_1
684+
getter: <testLibraryFragment>::@getter::a#element
685+
getters
686+
synthetic static get a
687+
firstFragment: <testLibraryFragment>::@getter::a
688+
returnType: A
689+
''');
690+
}
691+
594692
test_const_finalField_hasConstConstructor() async {
595693
var library = await buildLibrary(r'''
596694
class C {

0 commit comments

Comments
 (0)