Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4ccf7b8

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Don't set type for StringLiteral(s) in directives.
[email protected] Change-Id: Ie34d481c5ef07008d38aee1e89f1beb8a313590a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103460 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent caac50d commit 4ccf7b8

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

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

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ class AstBinaryReader {
3333
/// Set to `true` when this reader is used to lazily read its unit.
3434
bool isLazy = false;
3535

36+
/// Whether we are reading a directive.
37+
///
38+
/// [StringLiteral]s in directives are not actual expressions, and don't need
39+
/// a type. Moreover, when we are reading `dart:core` imports, the type
40+
/// provider is not ready yet, so we cannot access type `String`.
41+
bool _isReadingDirective = false;
42+
3643
AstBinaryReader(this._unitContext);
3744

3845
InterfaceType get _boolType => _unitContext.typeProvider.boolType;
@@ -151,9 +158,13 @@ class AstBinaryReader {
151158
}
152159

153160
AdjacentStrings _read_adjacentStrings(LinkedNode data) {
154-
return astFactory.adjacentStrings(
161+
var node = astFactory.adjacentStrings(
155162
_readNodeList(data.adjacentStrings_strings),
156-
)..staticType = _stringType;
163+
);
164+
if (!_isReadingDirective) {
165+
node.staticType = _stringType;
166+
}
167+
return node;
157168
}
158169

159170
Annotation _read_annotation(LinkedNode data) {
@@ -559,6 +570,7 @@ class AstBinaryReader {
559570

560571
ExportDirective _read_exportDirective(LinkedNode data) {
561572
timerAstBinaryReaderDirective.start();
573+
_isReadingDirective = true;
562574
try {
563575
var node = astFactory.exportDirective(
564576
_readNode(data.annotatedNode_comment),
@@ -572,6 +584,7 @@ class AstBinaryReader {
572584
LazyDirective.setData(node, data);
573585
return node;
574586
} finally {
587+
_isReadingDirective = false;
575588
timerAstBinaryReaderDirective.stop();
576589
}
577590
}
@@ -887,6 +900,7 @@ class AstBinaryReader {
887900

888901
ImportDirective _read_importDirective(LinkedNode data) {
889902
timerAstBinaryReaderDirective.start();
903+
_isReadingDirective = true;
890904
try {
891905
SimpleIdentifier prefix;
892906
if (data.importDirective_prefix.isNotEmpty) {
@@ -911,6 +925,7 @@ class AstBinaryReader {
911925
LazyDirective.setData(node, data);
912926
return node;
913927
} finally {
928+
_isReadingDirective = false;
914929
timerAstBinaryReaderDirective.stop();
915930
}
916931
}
@@ -1003,6 +1018,7 @@ class AstBinaryReader {
10031018

10041019
LibraryDirective _read_libraryDirective(LinkedNode data) {
10051020
timerAstBinaryReaderDirective.start();
1021+
_isReadingDirective = true;
10061022
try {
10071023
var node = astFactory.libraryDirective(
10081024
_readNode(data.annotatedNode_comment),
@@ -1014,6 +1030,7 @@ class AstBinaryReader {
10141030
LazyDirective.setData(node, data);
10151031
return node;
10161032
} finally {
1033+
_isReadingDirective = false;
10171034
timerAstBinaryReaderDirective.stop();
10181035
}
10191036
}
@@ -1156,6 +1173,7 @@ class AstBinaryReader {
11561173

11571174
PartDirective _read_partDirective(LinkedNode data) {
11581175
timerAstBinaryReaderDirective.start();
1176+
_isReadingDirective = true;
11591177
try {
11601178
var node = astFactory.partDirective(
11611179
_readNode(data.annotatedNode_comment),
@@ -1167,12 +1185,14 @@ class AstBinaryReader {
11671185
LazyDirective.setData(node, data);
11681186
return node;
11691187
} finally {
1188+
_isReadingDirective = false;
11701189
timerAstBinaryReaderDirective.stop();
11711190
}
11721191
}
11731192

11741193
PartOfDirective _read_partOfDirective(LinkedNode data) {
11751194
timerAstBinaryReaderDirective.start();
1195+
_isReadingDirective = true;
11761196
try {
11771197
var node = astFactory.partOfDirective(
11781198
_readNode(data.annotatedNode_comment),
@@ -1186,6 +1206,7 @@ class AstBinaryReader {
11861206
LazyDirective.setData(node, data);
11871207
return node;
11881208
} finally {
1209+
_isReadingDirective = false;
11891210
timerAstBinaryReaderDirective.stop();
11901211
}
11911212
}
@@ -1324,10 +1345,11 @@ class AstBinaryReader {
13241345
}
13251346

13261347
SimpleStringLiteral _read_simpleStringLiteral(LinkedNode data) {
1327-
// TODO(scheglov) restore staticType
1328-
return AstTestFactory.string2(data.simpleStringLiteral_value)
1329-
// ..staticType = _stringType
1330-
;
1348+
var node = AstTestFactory.string2(data.simpleStringLiteral_value);
1349+
if (!_isReadingDirective) {
1350+
node.staticType = _stringType;
1351+
}
1352+
return node;
13311353
}
13321354

13331355
SpreadElement _read_spreadElement(LinkedNode data) {

0 commit comments

Comments
 (0)