Version 2.18.0-131.0.dev
Merge commit '58c84272bc871eb3dba311226d48698aa7a3be47' into 'dev'
diff --git a/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart b/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart
index 299fa4e..4f05563 100644
--- a/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart
+++ b/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart
@@ -26552,8 +26552,16 @@
}
final notebookSelectorJson = json['notebookSelector'];
final notebookSelector = (notebookSelectorJson as List<Object?>)
- .map((item) => NotebookDocumentSyncOptionsNotebookSelector.fromJson(
- item as Map<String, Object?>))
+ .map((item) => NotebookDocumentSyncOptionsNotebookSelector.canParse(
+ item, nullLspJsonReporter)
+ ? Either2<NotebookDocumentSyncOptionsNotebookSelector, NotebookDocumentSyncOptionsNotebookSelector2>.t1(
+ NotebookDocumentSyncOptionsNotebookSelector.fromJson(
+ item as Map<String, Object?>))
+ : (NotebookDocumentSyncOptionsNotebookSelector2.canParse(item, nullLspJsonReporter)
+ ? Either2<NotebookDocumentSyncOptionsNotebookSelector,
+ NotebookDocumentSyncOptionsNotebookSelector2>.t2(
+ NotebookDocumentSyncOptionsNotebookSelector2.fromJson(item as Map<String, Object?>))
+ : (throw '''$item was not one of (NotebookDocumentSyncOptionsNotebookSelector, NotebookDocumentSyncOptionsNotebookSelector2)''')))
.toList();
final saveJson = json['save'];
final save = saveJson as bool?;
@@ -26564,7 +26572,9 @@
}
/// The notebooks to be synced
- final List<NotebookDocumentSyncOptionsNotebookSelector> notebookSelector;
+ final List<
+ Either2<NotebookDocumentSyncOptionsNotebookSelector,
+ NotebookDocumentSyncOptionsNotebookSelector2>> notebookSelector;
/// Whether save notification should be forwarded to the server. Will only be
/// honored if mode === `notebook`.
@@ -26572,8 +26582,7 @@
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
- __result['notebookSelector'] =
- notebookSelector.map((item) => item.toJson()).toList();
+ __result['notebookSelector'] = notebookSelector;
if (save != null) {
__result['save'] = save;
}
@@ -26595,10 +26604,12 @@
}
if (!((notebookSelector is List<Object?> &&
(notebookSelector.every((item) =>
- NotebookDocumentSyncOptionsNotebookSelector.canParse(
- item, reporter)))))) {
+ (NotebookDocumentSyncOptionsNotebookSelector.canParse(
+ item, reporter) ||
+ NotebookDocumentSyncOptionsNotebookSelector2.canParse(
+ item, reporter))))))) {
reporter.reportError(
- 'must be of type List<NotebookDocumentSyncOptionsNotebookSelector>');
+ 'must be of type List<Either2<NotebookDocumentSyncOptionsNotebookSelector, NotebookDocumentSyncOptionsNotebookSelector2>>');
return false;
}
} finally {
@@ -26628,8 +26639,12 @@
return listEqual(
notebookSelector,
other.notebookSelector,
- (NotebookDocumentSyncOptionsNotebookSelector a,
- NotebookDocumentSyncOptionsNotebookSelector b) =>
+ (Either2<NotebookDocumentSyncOptionsNotebookSelector,
+ NotebookDocumentSyncOptionsNotebookSelector2>
+ a,
+ Either2<NotebookDocumentSyncOptionsNotebookSelector,
+ NotebookDocumentSyncOptionsNotebookSelector2>
+ b) =>
a == b) &&
save == other.save &&
true;
@@ -26715,6 +26730,74 @@
String toString() => jsonEncoder.convert(toJson());
}
+class NotebookDocumentSyncOptionsCells2 implements ToJsonable {
+ static const jsonHandler = LspJsonHandler(
+ NotebookDocumentSyncOptionsCells2.canParse,
+ NotebookDocumentSyncOptionsCells2.fromJson,
+ );
+
+ NotebookDocumentSyncOptionsCells2({
+ required this.language,
+ });
+ static NotebookDocumentSyncOptionsCells2 fromJson(Map<String, Object?> json) {
+ final languageJson = json['language'];
+ final language = languageJson as String;
+ return NotebookDocumentSyncOptionsCells2(
+ language: language,
+ );
+ }
+
+ final String language;
+
+ Map<String, Object?> toJson() {
+ var __result = <String, Object?>{};
+ __result['language'] = language;
+ return __result;
+ }
+
+ static bool canParse(Object? obj, LspJsonReporter reporter) {
+ if (obj is Map<String, Object?>) {
+ reporter.push('language');
+ try {
+ if (!obj.containsKey('language')) {
+ reporter.reportError('must not be undefined');
+ return false;
+ }
+ final language = obj['language'];
+ if (language == null) {
+ reporter.reportError('must not be null');
+ return false;
+ }
+ if (!(language is String)) {
+ reporter.reportError('must be of type String');
+ return false;
+ }
+ } finally {
+ reporter.pop();
+ }
+ return true;
+ } else {
+ reporter.reportError('must be of type NotebookDocumentSyncOptionsCells2');
+ return false;
+ }
+ }
+
+ @override
+ bool operator ==(Object other) {
+ if (other is NotebookDocumentSyncOptionsCells2 &&
+ other.runtimeType == NotebookDocumentSyncOptionsCells2) {
+ return language == other.language && true;
+ }
+ return false;
+ }
+
+ @override
+ int get hashCode => language.hashCode;
+
+ @override
+ String toString() => jsonEncoder.convert(toJson());
+}
+
class NotebookDocumentSyncOptionsNotebookSelector implements ToJsonable {
static const jsonHandler = LspJsonHandler(
NotebookDocumentSyncOptionsNotebookSelector.canParse,
@@ -26722,34 +26805,33 @@
);
NotebookDocumentSyncOptionsNotebookSelector({
- required this.cells,
- this.notebookDocument,
+ this.cells,
+ required this.notebookDocument,
});
static NotebookDocumentSyncOptionsNotebookSelector fromJson(
Map<String, Object?> json) {
final cellsJson = json['cells'];
- final cells = (cellsJson as List<Object?>)
- .map((item) => NotebookDocumentSyncOptionsCells.fromJson(
+ final cells = (cellsJson as List<Object?>?)
+ ?.map((item) => NotebookDocumentSyncOptionsCells.fromJson(
item as Map<String, Object?>))
.toList();
final notebookDocumentJson = json['notebookDocument'];
- final notebookDocument = notebookDocumentJson == null
- ? null
- : ((NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter) ||
- NotebookDocumentFilter2.canParse(
- notebookDocumentJson, nullLspJsonReporter) ||
- NotebookDocumentFilter3.canParse(
- notebookDocumentJson, nullLspJsonReporter))
- ? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t1(
- NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter)
- ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t1(
- NotebookDocumentFilter1.fromJson(
- notebookDocumentJson as Map<String, Object?>))
- : (NotebookDocumentFilter2.canParse(notebookDocumentJson, nullLspJsonReporter)
- ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t2(
- NotebookDocumentFilter2.fromJson(notebookDocumentJson as Map<String, Object?>))
- : (NotebookDocumentFilter3.canParse(notebookDocumentJson, nullLspJsonReporter) ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t3(NotebookDocumentFilter3.fromJson(notebookDocumentJson as Map<String, Object?>)) : (throw '''$notebookDocumentJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)'''))))
- : (notebookDocumentJson is String ? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t2(notebookDocumentJson) : (throw '''$notebookDocumentJson was not one of (Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String)''')));
+ final notebookDocument = (NotebookDocumentFilter1.canParse(
+ notebookDocumentJson, nullLspJsonReporter) ||
+ NotebookDocumentFilter2.canParse(
+ notebookDocumentJson, nullLspJsonReporter) ||
+ NotebookDocumentFilter3.canParse(
+ notebookDocumentJson, nullLspJsonReporter))
+ ? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t1(
+ NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter)
+ ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t1(
+ NotebookDocumentFilter1.fromJson(
+ notebookDocumentJson as Map<String, Object?>))
+ : (NotebookDocumentFilter2.canParse(notebookDocumentJson, nullLspJsonReporter)
+ ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t2(
+ NotebookDocumentFilter2.fromJson(notebookDocumentJson as Map<String, Object?>))
+ : (NotebookDocumentFilter3.canParse(notebookDocumentJson, nullLspJsonReporter) ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t3(NotebookDocumentFilter3.fromJson(notebookDocumentJson as Map<String, Object?>)) : (throw '''$notebookDocumentJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)'''))))
+ : (notebookDocumentJson is String ? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t2(notebookDocumentJson) : (throw '''$notebookDocumentJson was not one of (Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String)'''));
return NotebookDocumentSyncOptionsNotebookSelector(
cells: cells,
notebookDocument: notebookDocument,
@@ -26757,21 +26839,21 @@
}
/// The cells of the matching notebook to be synced.
- final List<NotebookDocumentSyncOptionsCells> cells;
+ final List<NotebookDocumentSyncOptionsCells>? cells;
/// The notebook to be synced If a string value is provided it matches against
/// the notebook type. '*' matches every notebook.
final Either2<
Either3<NotebookDocumentFilter1, NotebookDocumentFilter2,
NotebookDocumentFilter3>,
- String>? notebookDocument;
+ String> notebookDocument;
Map<String, Object?> toJson() {
var __result = <String, Object?>{};
- __result['cells'] = cells.map((item) => item.toJson()).toList();
- if (notebookDocument != null) {
- __result['notebookDocument'] = notebookDocument;
+ if (cells != null) {
+ __result['cells'] = cells?.map((item) => item.toJson()).toList();
}
+ __result['notebookDocument'] = notebookDocument;
return __result;
}
@@ -26779,18 +26861,12 @@
if (obj is Map<String, Object?>) {
reporter.push('cells');
try {
- if (!obj.containsKey('cells')) {
- reporter.reportError('must not be undefined');
- return false;
- }
final cells = obj['cells'];
- if (cells == null) {
- reporter.reportError('must not be null');
- return false;
- }
- if (!((cells is List<Object?> &&
- (cells.every((item) =>
- NotebookDocumentSyncOptionsCells.canParse(item, reporter)))))) {
+ if (cells != null &&
+ !((cells is List<Object?> &&
+ (cells.every((item) =>
+ NotebookDocumentSyncOptionsCells.canParse(
+ item, reporter)))))) {
reporter.reportError(
'must be of type List<NotebookDocumentSyncOptionsCells>');
return false;
@@ -26800,14 +26876,19 @@
}
reporter.push('notebookDocument');
try {
+ if (!obj.containsKey('notebookDocument')) {
+ reporter.reportError('must not be undefined');
+ return false;
+ }
final notebookDocument = obj['notebookDocument'];
- if (notebookDocument != null &&
- !(((NotebookDocumentFilter1.canParse(notebookDocument, reporter) ||
- NotebookDocumentFilter2.canParse(
- notebookDocument, reporter) ||
- NotebookDocumentFilter3.canParse(
- notebookDocument, reporter)) ||
- notebookDocument is String))) {
+ if (notebookDocument == null) {
+ reporter.reportError('must not be null');
+ return false;
+ }
+ if (!(((NotebookDocumentFilter1.canParse(notebookDocument, reporter) ||
+ NotebookDocumentFilter2.canParse(notebookDocument, reporter) ||
+ NotebookDocumentFilter3.canParse(notebookDocument, reporter)) ||
+ notebookDocument is String))) {
reporter.reportError(
'must be of type Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>');
return false;
@@ -26849,6 +26930,140 @@
String toString() => jsonEncoder.convert(toJson());
}
+class NotebookDocumentSyncOptionsNotebookSelector2 implements ToJsonable {
+ static const jsonHandler = LspJsonHandler(
+ NotebookDocumentSyncOptionsNotebookSelector2.canParse,
+ NotebookDocumentSyncOptionsNotebookSelector2.fromJson,
+ );
+
+ NotebookDocumentSyncOptionsNotebookSelector2({
+ required this.cells,
+ this.notebookDocument,
+ });
+ static NotebookDocumentSyncOptionsNotebookSelector2 fromJson(
+ Map<String, Object?> json) {
+ final cellsJson = json['cells'];
+ final cells = (cellsJson as List<Object?>)
+ .map((item) => NotebookDocumentSyncOptionsCells2.fromJson(
+ item as Map<String, Object?>))
+ .toList();
+ final notebookDocumentJson = json['notebookDocument'];
+ final notebookDocument = notebookDocumentJson == null
+ ? null
+ : ((NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter) ||
+ NotebookDocumentFilter2.canParse(
+ notebookDocumentJson, nullLspJsonReporter) ||
+ NotebookDocumentFilter3.canParse(
+ notebookDocumentJson, nullLspJsonReporter))
+ ? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t1(
+ NotebookDocumentFilter1.canParse(notebookDocumentJson, nullLspJsonReporter)
+ ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t1(
+ NotebookDocumentFilter1.fromJson(
+ notebookDocumentJson as Map<String, Object?>))
+ : (NotebookDocumentFilter2.canParse(notebookDocumentJson, nullLspJsonReporter)
+ ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t2(
+ NotebookDocumentFilter2.fromJson(notebookDocumentJson as Map<String, Object?>))
+ : (NotebookDocumentFilter3.canParse(notebookDocumentJson, nullLspJsonReporter) ? Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>.t3(NotebookDocumentFilter3.fromJson(notebookDocumentJson as Map<String, Object?>)) : (throw '''$notebookDocumentJson was not one of (NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3)'''))))
+ : (notebookDocumentJson is String ? Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>.t2(notebookDocumentJson) : (throw '''$notebookDocumentJson was not one of (Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String)''')));
+ return NotebookDocumentSyncOptionsNotebookSelector2(
+ cells: cells,
+ notebookDocument: notebookDocument,
+ );
+ }
+
+ /// The cells of the matching notebook to be synced.
+ final List<NotebookDocumentSyncOptionsCells2> cells;
+
+ /// The notebook to be synced If a string value is provided it matches against
+ /// the notebook type. '*' matches every notebook.
+ final Either2<
+ Either3<NotebookDocumentFilter1, NotebookDocumentFilter2,
+ NotebookDocumentFilter3>,
+ String>? notebookDocument;
+
+ Map<String, Object?> toJson() {
+ var __result = <String, Object?>{};
+ __result['cells'] = cells.map((item) => item.toJson()).toList();
+ if (notebookDocument != null) {
+ __result['notebookDocument'] = notebookDocument;
+ }
+ return __result;
+ }
+
+ static bool canParse(Object? obj, LspJsonReporter reporter) {
+ if (obj is Map<String, Object?>) {
+ reporter.push('cells');
+ try {
+ if (!obj.containsKey('cells')) {
+ reporter.reportError('must not be undefined');
+ return false;
+ }
+ final cells = obj['cells'];
+ if (cells == null) {
+ reporter.reportError('must not be null');
+ return false;
+ }
+ if (!((cells is List<Object?> &&
+ (cells.every((item) => NotebookDocumentSyncOptionsCells2.canParse(
+ item, reporter)))))) {
+ reporter.reportError(
+ 'must be of type List<NotebookDocumentSyncOptionsCells2>');
+ return false;
+ }
+ } finally {
+ reporter.pop();
+ }
+ reporter.push('notebookDocument');
+ try {
+ final notebookDocument = obj['notebookDocument'];
+ if (notebookDocument != null &&
+ !(((NotebookDocumentFilter1.canParse(notebookDocument, reporter) ||
+ NotebookDocumentFilter2.canParse(
+ notebookDocument, reporter) ||
+ NotebookDocumentFilter3.canParse(
+ notebookDocument, reporter)) ||
+ notebookDocument is String))) {
+ reporter.reportError(
+ 'must be of type Either2<Either3<NotebookDocumentFilter1, NotebookDocumentFilter2, NotebookDocumentFilter3>, String>');
+ return false;
+ }
+ } finally {
+ reporter.pop();
+ }
+ return true;
+ } else {
+ reporter.reportError(
+ 'must be of type NotebookDocumentSyncOptionsNotebookSelector2');
+ return false;
+ }
+ }
+
+ @override
+ bool operator ==(Object other) {
+ if (other is NotebookDocumentSyncOptionsNotebookSelector2 &&
+ other.runtimeType == NotebookDocumentSyncOptionsNotebookSelector2) {
+ return listEqual(
+ cells,
+ other.cells,
+ (NotebookDocumentSyncOptionsCells2 a,
+ NotebookDocumentSyncOptionsCells2 b) =>
+ a == b) &&
+ notebookDocument == other.notebookDocument &&
+ true;
+ }
+ return false;
+ }
+
+ @override
+ int get hashCode => Object.hash(
+ lspHashCode(cells),
+ notebookDocument,
+ );
+
+ @override
+ String toString() => jsonEncoder.convert(toJson());
+}
+
/// Registration options specific to a notebook.
/// @since 3.17.0
class NotebookDocumentSyncRegistrationOptions
@@ -26872,8 +27087,16 @@
final id = idJson as String?;
final notebookSelectorJson = json['notebookSelector'];
final notebookSelector = (notebookSelectorJson as List<Object?>)
- .map((item) => NotebookDocumentSyncOptionsNotebookSelector.fromJson(
- item as Map<String, Object?>))
+ .map((item) => NotebookDocumentSyncOptionsNotebookSelector.canParse(
+ item, nullLspJsonReporter)
+ ? Either2<NotebookDocumentSyncOptionsNotebookSelector, NotebookDocumentSyncOptionsNotebookSelector2>.t1(
+ NotebookDocumentSyncOptionsNotebookSelector.fromJson(
+ item as Map<String, Object?>))
+ : (NotebookDocumentSyncOptionsNotebookSelector2.canParse(item, nullLspJsonReporter)
+ ? Either2<NotebookDocumentSyncOptionsNotebookSelector,
+ NotebookDocumentSyncOptionsNotebookSelector2>.t2(
+ NotebookDocumentSyncOptionsNotebookSelector2.fromJson(item as Map<String, Object?>))
+ : (throw '''$item was not one of (NotebookDocumentSyncOptionsNotebookSelector, NotebookDocumentSyncOptionsNotebookSelector2)''')))
.toList();
final saveJson = json['save'];
final save = saveJson as bool?;
@@ -26889,7 +27112,9 @@
final String? id;
/// The notebooks to be synced
- final List<NotebookDocumentSyncOptionsNotebookSelector> notebookSelector;
+ final List<
+ Either2<NotebookDocumentSyncOptionsNotebookSelector,
+ NotebookDocumentSyncOptionsNotebookSelector2>> notebookSelector;
/// Whether save notification should be forwarded to the server. Will only be
/// honored if mode === `notebook`.
@@ -26900,8 +27125,7 @@
if (id != null) {
__result['id'] = id;
}
- __result['notebookSelector'] =
- notebookSelector.map((item) => item.toJson()).toList();
+ __result['notebookSelector'] = notebookSelector;
if (save != null) {
__result['save'] = save;
}
@@ -26933,10 +27157,12 @@
}
if (!((notebookSelector is List<Object?> &&
(notebookSelector.every((item) =>
- NotebookDocumentSyncOptionsNotebookSelector.canParse(
- item, reporter)))))) {
+ (NotebookDocumentSyncOptionsNotebookSelector.canParse(
+ item, reporter) ||
+ NotebookDocumentSyncOptionsNotebookSelector2.canParse(
+ item, reporter))))))) {
reporter.reportError(
- 'must be of type List<NotebookDocumentSyncOptionsNotebookSelector>');
+ 'must be of type List<Either2<NotebookDocumentSyncOptionsNotebookSelector, NotebookDocumentSyncOptionsNotebookSelector2>>');
return false;
}
} finally {
@@ -26968,8 +27194,12 @@
listEqual(
notebookSelector,
other.notebookSelector,
- (NotebookDocumentSyncOptionsNotebookSelector a,
- NotebookDocumentSyncOptionsNotebookSelector b) =>
+ (Either2<NotebookDocumentSyncOptionsNotebookSelector,
+ NotebookDocumentSyncOptionsNotebookSelector2>
+ a,
+ Either2<NotebookDocumentSyncOptionsNotebookSelector,
+ NotebookDocumentSyncOptionsNotebookSelector2>
+ b) =>
a == b) &&
save == other.save &&
true;
diff --git a/pkg/analysis_server/test/analysis/notification_outline_test.dart b/pkg/analysis_server/test/analysis/notification_outline_test.dart
index 262673b..4347bad 100644
--- a/pkg/analysis_server/test/analysis/notification_outline_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_outline_test.dart
@@ -96,6 +96,12 @@
}
Future<void> test_libraryName_hasPartOfDirective() async {
+ newFile('$testPackageLibPath/a.dart', r'''
+library lib;
+
+part 'test.dart';
+''');
+
addTestFile('''
part of my.lib;
''');
diff --git a/pkg/analysis_server/test/search/element_references_test.dart b/pkg/analysis_server/test/search/element_references_test.dart
index de8f23e..8e86727 100644
--- a/pkg/analysis_server/test/search/element_references_test.dart
+++ b/pkg/analysis_server/test/search/element_references_test.dart
@@ -742,8 +742,8 @@
}
''');
await findElementReferences('fff(p) {}', false);
- expect(results, hasLength(1));
- assertHasResult(SearchResultKind.INVOCATION, 'fff(10);');
+ // A part without library, no results.
+ expect(results, isEmpty);
}
Future<void> test_parameter() async {
diff --git a/pkg/analysis_server/test/services/completion/dart/keyword_contributor_test.dart b/pkg/analysis_server/test/services/completion/dart/keyword_contributor_test.dart
index 0d839ec..f6e0668 100644
--- a/pkg/analysis_server/test/services/completion/dart/keyword_contributor_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/keyword_contributor_test.dart
@@ -2272,6 +2272,7 @@
assertSuggestKeywords([]);
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49046')
Future<void> test_part_of() async {
addTestSource('part of foo;^');
await computeSuggestions();
diff --git a/pkg/analysis_server/test/src/services/correction/fix/add_missing_parameter_required_test.dart b/pkg/analysis_server/test/src/services/correction/fix/add_missing_parameter_required_test.dart
index 74236cce..7c1d58c 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/add_missing_parameter_required_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/add_missing_parameter_required_test.dart
@@ -105,6 +105,7 @@
''');
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49046')
Future<void> test_function_hasZero_partOfName_noLibrary() async {
await resolveTestCode('''
part of my_lib;
diff --git a/pkg/analysis_server/test/src/services/correction/fix/create_constructor_test.dart b/pkg/analysis_server/test/src/services/correction/fix/create_constructor_test.dart
index 31ee456..196a197 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/create_constructor_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/create_constructor_test.dart
@@ -79,6 +79,7 @@
''', target: a);
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49046')
Future<void> test_inPart_partOfName_noLibrary() async {
await resolveTestCode('''
part of my_lib;
diff --git a/pkg/analysis_server/test/src/services/correction/fix/create_field_test.dart b/pkg/analysis_server/test/src/services/correction/fix/create_field_test.dart
index af26bc4..0cc45cd 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/create_field_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/create_field_test.dart
@@ -383,6 +383,7 @@
});
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49046')
Future<void> test_inPart_self() async {
await resolveTestCode('''
part of lib;
diff --git a/pkg/analysis_server/test/src/services/correction/fix/create_getter_test.dart b/pkg/analysis_server/test/src/services/correction/fix/create_getter_test.dart
index 7566168..f7f443f 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/create_getter_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/create_getter_test.dart
@@ -326,6 +326,7 @@
});
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49046')
Future<void> test_qualified_instance_inPart_self() async {
await resolveTestCode('''
part of lib;
diff --git a/pkg/analysis_server/test/src/services/correction/fix/create_setter_test.dart b/pkg/analysis_server/test/src/services/correction/fix/create_setter_test.dart
index fea7674..db18da2 100644
--- a/pkg/analysis_server/test/src/services/correction/fix/create_setter_test.dart
+++ b/pkg/analysis_server/test/src/services/correction/fix/create_setter_test.dart
@@ -320,6 +320,7 @@
});
}
+ @FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/49046')
Future<void> test_qualified_instance_inPart_self() async {
await resolveTestCode('''
part of lib;
diff --git a/pkg/analysis_server/tool/lsp_spec/typescript_parser.dart b/pkg/analysis_server/tool/lsp_spec/typescript_parser.dart
index 6cf66db..d2b2eab 100644
--- a/pkg/analysis_server/tool/lsp_spec/typescript_parser.dart
+++ b/pkg/analysis_server/tool/lsp_spec/typescript_parser.dart
@@ -253,6 +253,10 @@
final List<Token> _tokens;
int _current = 0;
final List<AstNode> _nodes = [];
+
+ /// A set of names already used (or reserved) by nodes.
+ final Set<String> _nodeNames = {};
+
Parser(this._tokens);
bool get _isAtEnd => _peek().type == TokenType.EOF;
@@ -260,7 +264,7 @@
List<AstNode> parse() {
if (_nodes.isEmpty) {
while (!_isAtEnd) {
- _nodes.add(_topLevel());
+ _addNode(_topLevel());
// Consume any trailing semicolons.
_match([TokenType.SEMI_COLON]);
}
@@ -268,6 +272,13 @@
return _nodes;
}
+ /// Adds [node] to the current list and prevents its name from being used
+ /// by generated interfaces.
+ void _addNode(AstNode node) {
+ _nodeNames.add(node.name);
+ _nodes.add(node);
+ }
+
/// Returns the current token and moves to the next.
Token _advance() => _tokenAt(_current++);
@@ -425,6 +436,28 @@
allowsNull: canBeNull, allowsUndefined: canBeUndefined);
}
+ /// Gets an available name for a node.
+ ///
+ /// If the computed name is already used, a number will be appended to the
+ /// end.
+ String _getAvailableName(String containerName, String? fieldName) {
+ final name = _joinNames(containerName, fieldName ?? '');
+ final requiresSuffix = fieldName == null;
+ // If the name has already been taken, try appending a number and try
+ // again.
+ String generatedName;
+ var suffixIndex = 1;
+ do {
+ if (suffixIndex > 20) {
+ throw 'Failed to generate an available name for $name';
+ }
+ generatedName =
+ requiresSuffix || suffixIndex > 1 ? '$name$suffixIndex' : name;
+ suffixIndex++;
+ } while (_nodeNames.contains(generatedName));
+ return generatedName;
+ }
+
Indexer _indexer(String containerName, Comment? leadingComment) {
final indexer = _field(containerName, leadingComment);
_consume(TokenType.RIGHT_BRACKET, 'Expected ]');
@@ -592,9 +625,7 @@
if (includeUndefined) {
types.add(Type.Undefined);
}
- var typeIndex = 0;
while (true) {
- typeIndex++;
TypeBase type;
if (_match([TokenType.LEFT_BRACE])) {
// Inline interfaces.
@@ -613,13 +644,8 @@
type = MapType(indexer.indexType, indexer.valueType);
} else {
// Add a synthetic interface to the parsers list of nodes to represent this type.
- // If we have no fieldName to base the synthetic name from, we should use
- // the index of this type, for example in:
- // type Foo = { [..] } | { [...] }
- // we will generate Foo1 and Foo2 for the types.
- final nameSuffix = fieldName ?? '$typeIndex';
- final generatedName = _joinNames(containerName, nameSuffix);
- _nodes.add(InlineInterface(generatedName, members));
+ final generatedName = _getAvailableName(containerName, fieldName);
+ _addNode(InlineInterface(generatedName, members));
// Record the type as a simple type that references this interface.
type = Type.identifier(generatedName);
}
@@ -705,6 +731,10 @@
TypeAlias _typeAlias(Comment? leadingComment) {
final name = _consume(TokenType.IDENTIFIER, 'Expected identifier');
_consume(TokenType.EQUAL, 'Expected =');
+ // Reserve the name for this alias before we start reading its type so that
+ // inline/literal types will not try to compute the same name if they do
+ // not have field names.
+ _nodeNames.add(name.lexeme);
final type = _type(name.lexeme, null);
if (!_isAtEnd) {
_consume(TokenType.SEMI_COLON, 'Expected ;');
diff --git a/pkg/analyzer/lib/dart/analysis/results.dart b/pkg/analyzer/lib/dart/analysis/results.dart
index 97198d9..200ebaf 100644
--- a/pkg/analyzer/lib/dart/analysis/results.dart
+++ b/pkg/analyzer/lib/dart/analysis/results.dart
@@ -195,6 +195,22 @@
CompilationUnit get unit;
}
+/// The type of [InvalidResult] returned when the file is a part, and its
+/// containing library is not known.
+///
+/// Clients may not extend, implement or mix-in this class.
+///
+/// TODO(scheglov) Add an error that points at the `part of` location.
+abstract class PartWithoutLibraryResult
+ implements
+ InvalidResult,
+ SomeErrorsResult,
+ SomeResolvedUnitResult,
+ SomeUnitElementResult {
+ /// The absolute and normalized path of the file.
+ String get path;
+}
+
/// The result of building resolved AST(s) for the whole library.
///
/// Clients may not extend, implement or mix-in this class.
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index c3aaba2..1160d53 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -84,7 +84,7 @@
/// TODO(scheglov) Clean up the list of implicitly analyzed files.
class AnalysisDriver implements AnalysisDriverGeneric {
/// The version of data format, should be incremented on every format change.
- static const int DATA_VERSION = 219;
+ static const int DATA_VERSION = 220;
/// The number of exception contexts allowed to write. Once this field is
/// zero, we stop writing any new exception contexts in this process.
@@ -159,7 +159,7 @@
/// The mapping from the files for which analysis was requested using
/// [getResult] to the [Completer]s to report the result.
- final _requestedFiles = <String, List<Completer<ResolvedUnitResult>>>{};
+ final _requestedFiles = <String, List<Completer<SomeResolvedUnitResult>>>{};
/// The mapping from the files for which analysis was requested using
/// [getResolvedLibrary] to the [Completer]s to report the result.
@@ -182,35 +182,17 @@
/// The mapping from the files for which errors were requested using
/// [getErrors] to the [Completer]s to report the result.
- final _errorsRequestedFiles = <String, List<Completer<ErrorsResult>>>{};
-
- /// The requests from [_errorsRequestedFiles] for files which were found to
- /// be parts without known libraries, so delayed.
- final _errorsRequestedParts = <String, List<Completer<ErrorsResult>>>{};
+ final _errorsRequestedFiles = <String, List<Completer<SomeErrorsResult>>>{};
/// The mapping from the files for which the index was requested using
/// [getIndex] to the [Completer]s to report the result.
final _indexRequestedFiles =
- <String, List<Completer<AnalysisDriverUnitIndex>>>{};
+ <String, List<Completer<AnalysisDriverUnitIndex?>>>{};
/// The mapping from the files for which the unit element was requested using
/// [getUnitElement] to the [Completer]s to report the result.
final _unitElementRequestedFiles =
- <String, List<Completer<UnitElementResult>>>{};
-
- /// The mapping from the files for which the unit element was requested using
- /// [getUnitElement], and which were found to be parts without known
- /// libraries, to the [Completer]s to report the result.
- final _unitElementRequestedParts =
- <String, List<Completer<UnitElementResult>>>{};
-
- /// The mapping from the files for which analysis was requested using
- /// [getResult], and which were found to be parts without known libraries,
- /// to the [Completer]s to report the result.
- final _requestedParts = <String, List<Completer<ResolvedUnitResult>>>{};
-
- /// The set of part files that are currently scheduled for analysis.
- final _partsToAnalyze = <String>{};
+ <String, List<Completer<SomeUnitElementResult>>>{};
/// The controller for the [results] stream.
final _resultController = StreamController<Object>();
@@ -249,6 +231,11 @@
/// Whether `dart:core` has been transitively discovered.
bool _hasDartCoreDiscovered = false;
+ /// This flag is reset to `false` when a new file is added, because it
+ /// might be a library, so that some files that were disconnected parts
+ /// could be analyzed now.
+ bool _hasLibrariesDiscovered = false;
+
/// If testing data is being retained, a pointer to the object that is
/// retaining the testing data. Otherwise `null`.
final TestingData? testingData;
@@ -311,9 +298,7 @@
return hasPendingFileChanges ||
_fileTracker.hasChangedFiles ||
_requestedFiles.isNotEmpty ||
- _requestedParts.isNotEmpty ||
- _fileTracker.hasPendingFiles ||
- _partsToAnalyze.isNotEmpty;
+ _fileTracker.hasPendingFiles;
}
bool get hasPendingFileChanges => _pendingFileChanges.isNotEmpty;
@@ -455,11 +440,7 @@
if (_fileTracker.hasPendingFiles) {
return AnalysisDriverPriority.general;
}
- if (_errorsRequestedParts.isNotEmpty ||
- _requestedParts.isNotEmpty ||
- _partsToAnalyze.isNotEmpty ||
- _unitElementRequestedParts.isNotEmpty ||
- _pendingFileChangesCompleters.isNotEmpty) {
+ if (_pendingFileChangesCompleters.isNotEmpty) {
return AnalysisDriverPriority.general;
}
return AnalysisDriverPriority.nothing;
@@ -627,9 +608,9 @@
);
}
- var completer = Completer<ErrorsResult>();
+ var completer = Completer<SomeErrorsResult>();
_errorsRequestedFiles
- .putIfAbsent(path, () => <Completer<ErrorsResult>>[])
+ .putIfAbsent(path, () => <Completer<SomeErrorsResult>>[])
.add(completer);
_scheduler.notify(this);
return completer.future;
@@ -699,9 +680,9 @@
if (!_fsState.hasUri(path)) {
return Future.value();
}
- var completer = Completer<AnalysisDriverUnitIndex>();
+ var completer = Completer<AnalysisDriverUnitIndex?>();
_indexRequestedFiles
- .putIfAbsent(path, () => <Completer<AnalysisDriverUnitIndex>>[])
+ .putIfAbsent(path, () => <Completer<AnalysisDriverUnitIndex?>>[])
.add(completer);
_scheduler.notify(this);
return completer.future;
@@ -918,9 +899,9 @@
}
// Schedule analysis.
- var completer = Completer<ResolvedUnitResult>();
+ var completer = Completer<SomeResolvedUnitResult>();
_requestedFiles
- .putIfAbsent(path, () => <Completer<ResolvedUnitResult>>[])
+ .putIfAbsent(path, () => <Completer<SomeResolvedUnitResult>>[])
.add(completer);
_scheduler.notify(this);
return completer.future;
@@ -964,9 +945,9 @@
);
}
- var completer = Completer<UnitElementResult>();
+ var completer = Completer<SomeUnitElementResult>();
_unitElementRequestedFiles
- .putIfAbsent(path, () => <Completer<UnitElementResult>>[])
+ .putIfAbsent(path, () => <Completer<SomeUnitElementResult>>[])
.add(completer);
_scheduler.notify(this);
return completer.future;
@@ -1041,10 +1022,8 @@
@override
Future<void> performWork() async {
- if (!_hasDartCoreDiscovered) {
- _hasDartCoreDiscovered = true;
- _discoverDartCore();
- }
+ _discoverDartCore();
+ _discoverLibraries();
if (_resolveForCompletionRequests.isNotEmpty) {
final request = _resolveForCompletionRequests.removeLast();
@@ -1061,27 +1040,26 @@
// Analyze a requested file.
if (_requestedFiles.isNotEmpty) {
- String path = _requestedFiles.keys.first;
+ final path = _requestedFiles.keys.first;
+ final completers = _requestedFiles.remove(path)!;
+ _fileTracker.fileWasAnalyzed(path);
try {
- var result = await _computeAnalysisResult(path, withUnit: true);
- // If a part without a library, delay its analysis.
- if (result == null) {
- _requestedParts
- .putIfAbsent(path, () => [])
- .addAll(_requestedFiles.remove(path)!);
- return;
+ final result = await _computeAnalysisResult(path, withUnit: true);
+ final SomeResolvedUnitResult unitResult;
+ if (result != null) {
+ unitResult = result.unitResult!;
+ } else {
+ unitResult = PartWithoutLibraryResultImpl(
+ path: path,
+ );
}
- // Notify the completers.
- for (var completer in _requestedFiles.remove(path)!) {
- completer.complete(result.unitResult!);
+ for (final completer in completers) {
+ completer.complete(unitResult);
}
- // Remove from to be analyzed and produce it now.
- _fileTracker.fileWasAnalyzed(path);
- _resultController.add(result.unitResult!);
+ _resultController.add(unitResult);
} catch (exception, stackTrace) {
_reportException(path, exception, stackTrace);
- _fileTracker.fileWasAnalyzed(path);
- for (var completer in _requestedFiles.remove(path)!) {
+ for (final completer in completers) {
completer.completeError(exception, stackTrace);
}
_clearLibraryContextAfterException();
@@ -1112,14 +1090,10 @@
var completers = _errorsRequestedFiles.remove(path)!;
var result = await _computeErrors(
path: path,
- asIsIfPartWithoutLibrary: false,
);
- if (result != null) {
- for (var completer in completers) {
- completer.complete(result);
- }
- } else {
- _errorsRequestedParts.putIfAbsent(path, () => []).addAll(completers);
+ result ??= PartWithoutLibraryResultImpl(path: path);
+ for (var completer in completers) {
+ completer.complete(result);
}
return;
}
@@ -1127,7 +1101,7 @@
// Process an index request.
if (_indexRequestedFiles.isNotEmpty) {
String path = _indexRequestedFiles.keys.first;
- AnalysisDriverUnitIndex index = await _computeIndex(path);
+ final index = await _computeIndex(path);
for (var completer in _indexRequestedFiles.remove(path)!) {
completer.complete(index);
}
@@ -1137,16 +1111,11 @@
// Process a unit element request.
if (_unitElementRequestedFiles.isNotEmpty) {
String path = _unitElementRequestedFiles.keys.first;
- UnitElementResult? result = await _computeUnitElement(path);
var completers = _unitElementRequestedFiles.remove(path)!;
- if (result != null) {
- for (var completer in completers) {
- completer.complete(result);
- }
- } else {
- _unitElementRequestedParts
- .putIfAbsent(path, () => [])
- .addAll(completers);
+ SomeUnitElementResult? result = await _computeUnitElement(path);
+ result ??= PartWithoutLibraryResultImpl(path: path);
+ for (var completer in completers) {
+ completer.complete(result);
}
return;
}
@@ -1186,7 +1155,14 @@
try {
var result = await _computeAnalysisResult(path, withUnit: true);
if (result == null) {
- _partsToAnalyze.add(path);
+ // We report an invalid result (instead of silently ignoring
+ // this disconnected part) so that the listener of the stream
+ // knows, and for example removes all errors.
+ _resultController.add(
+ PartWithoutLibraryResultImpl(
+ path: path,
+ ),
+ );
} else {
_resultController.add(result.unitResult!);
}
@@ -1208,7 +1184,11 @@
var result = await _computeAnalysisResult(path,
withUnit: false, skipIfSameSignature: true);
if (result == null) {
- _partsToAnalyze.add(path);
+ _resultController.add(
+ PartWithoutLibraryResultImpl(
+ path: path,
+ ),
+ );
} else if (result.isUnchangedErrors) {
// We found that the set of errors is the same as we produced the
// last time, so we don't need to produce it again now.
@@ -1224,79 +1204,6 @@
}
return;
}
-
- // Analyze a requested part file.
- if (_requestedParts.isNotEmpty) {
- String path = _requestedParts.keys.first;
- try {
- var result = await _computeAnalysisResult(path,
- withUnit: true, asIsIfPartWithoutLibrary: true);
- result!;
- // Notify the completers.
- for (var completer in _requestedParts.remove(path)!) {
- completer.complete(result.unitResult!);
- }
- // Remove from to be analyzed and produce it now.
- _partsToAnalyze.remove(path);
- _resultController.add(result.unitResult!);
- } catch (exception, stackTrace) {
- _reportException(path, exception, stackTrace);
- _partsToAnalyze.remove(path);
- for (var completer in _requestedParts.remove(path)!) {
- completer.completeError(exception, stackTrace);
- }
- _clearLibraryContextAfterException();
- }
- return;
- }
-
- // Analyze a general part.
- if (_partsToAnalyze.isNotEmpty) {
- String path = _partsToAnalyze.first;
- _partsToAnalyze.remove(path);
- try {
- var withUnit = _priorityFiles.contains(path);
- if (withUnit) {
- var result = await _computeAnalysisResult(path,
- withUnit: true, asIsIfPartWithoutLibrary: true);
- _resultController.add(result!.unitResult!);
- } else {
- var result = await _computeAnalysisResult(path,
- withUnit: false, asIsIfPartWithoutLibrary: true);
- _resultController.add(result!.errorsResult!);
- }
- } catch (exception, stackTrace) {
- _reportException(path, exception, stackTrace);
- _clearLibraryContextAfterException();
- }
- return;
- }
-
- // Process a unit element request for a part.
- if (_unitElementRequestedParts.isNotEmpty) {
- String path = _unitElementRequestedParts.keys.first;
- var result =
- await _computeUnitElement(path, asIsIfPartWithoutLibrary: true);
- result!;
- for (var completer in _unitElementRequestedParts.remove(path)!) {
- completer.complete(result);
- }
- return;
- }
-
- // Compute errors in a part.
- if (_errorsRequestedParts.isNotEmpty) {
- var path = _errorsRequestedParts.keys.first;
- var completers = _errorsRequestedParts.remove(path)!;
- var result = await _computeErrors(
- path: path,
- asIsIfPartWithoutLibrary: true,
- );
- for (var completer in completers) {
- completer.complete(result);
- }
- return;
- }
}
/// Remove the file with the given [path] from the list of files to analyze.
@@ -1496,24 +1403,16 @@
});
}
- Future<ErrorsResult?> _computeErrors({
+ Future<SomeErrorsResult?> _computeErrors({
required String path,
- required bool asIsIfPartWithoutLibrary,
}) async {
- var analysisResult = await _computeAnalysisResult(path,
- withUnit: false, asIsIfPartWithoutLibrary: asIsIfPartWithoutLibrary);
-
- if (analysisResult == null) {
- return null;
- }
-
- return analysisResult.errorsResult;
+ var analysisResult = await _computeAnalysisResult(path, withUnit: false);
+ return analysisResult?.errorsResult;
}
- Future<AnalysisDriverUnitIndex> _computeIndex(String path) async {
- var analysisResult = await _computeAnalysisResult(path,
- withUnit: false, asIsIfPartWithoutLibrary: true);
- return analysisResult!._index!;
+ Future<AnalysisDriverUnitIndex?> _computeIndex(String path) async {
+ var analysisResult = await _computeAnalysisResult(path, withUnit: false);
+ return analysisResult?._index;
}
/// Return the newly computed resolution result of the library with the
@@ -1646,6 +1545,11 @@
/// The current workaround for this is to discover `dart:core` before any
/// analysis.
void _discoverDartCore() {
+ if (_hasDartCoreDiscovered) {
+ return;
+ }
+ _hasDartCoreDiscovered = true;
+
_fsState.getFileForUri(Uri.parse('dart:core')).map(
(file) {
file?.transitiveFiles;
@@ -1654,6 +1558,17 @@
);
}
+ void _discoverLibraries() {
+ if (_hasLibrariesDiscovered) {
+ return;
+ }
+ _hasLibrariesDiscovered = true;
+
+ for (final path in _fileTracker.addedFiles) {
+ _fsState.getFileForPath(path);
+ }
+ }
+
void _fillSalt() {
_fillSaltForUnlinked();
_fillSaltForElements();
diff --git a/pkg/analyzer/lib/src/dart/analysis/file_state.dart b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
index 4fc7f27..1bd5c9c 100644
--- a/pkg/analyzer/lib/src/dart/analysis/file_state.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/file_state.dart
@@ -235,7 +235,11 @@
/// Return `true` if the file does not have a `library` directive, and has a
/// `part of` directive, so is probably a part.
bool get isPart {
- return !_unlinked2!.hasLibraryDirective && _unlinked2!.hasPartOfDirective;
+ if (_unlinked2!.libraryDirective != null) {
+ return false;
+ }
+ return _unlinked2!.partOfNameDirective != null ||
+ _unlinked2!.partOfUriDirective != null;
}
/// If the file [isPart], return a currently know library the file is a part
@@ -578,13 +582,15 @@
}
static UnlinkedUnit serializeAstUnlinked2(CompilationUnit unit) {
+ UnlinkedLibraryDirective? libraryDirective;
+ UnlinkedLibraryAugmentationDirective? libraryAugmentationDirective;
+ UnlinkedPartOfNameDirective? partOfNameDirective;
+ UnlinkedPartOfUriDirective? partOfUriDirective;
var exports = <UnlinkedNamespaceDirective>[];
var imports = <UnlinkedNamespaceDirective>[];
var parts = <String>[];
var macroClasses = <MacroClass>[];
var hasDartCoreImport = false;
- var hasLibraryDirective = false;
- var hasPartOfDirective = false;
for (var directive in unit.directives) {
if (directive is ExportDirective) {
var builder = _serializeNamespaceDirective(directive);
@@ -595,13 +601,48 @@
if (builder.uri == 'dart:core') {
hasDartCoreImport = true;
}
+ } else if (directive is LibraryAugmentationDirective) {
+ final uri = directive.uri;
+ final uriStr = uri.stringValue;
+ if (uriStr != null) {
+ libraryAugmentationDirective = UnlinkedLibraryAugmentationDirective(
+ uri: uriStr,
+ uriRange: UnlinkedSourceRange(
+ offset: uri.offset,
+ length: uri.length,
+ ),
+ );
+ }
} else if (directive is LibraryDirective) {
- hasLibraryDirective = true;
+ libraryDirective = UnlinkedLibraryDirective(
+ name: directive.name.name,
+ );
} else if (directive is PartDirective) {
var uriStr = directive.uri.stringValue;
parts.add(uriStr ?? '');
} else if (directive is PartOfDirective) {
- hasPartOfDirective = true;
+ final libraryName = directive.libraryName;
+ final uri = directive.uri;
+ if (libraryName != null) {
+ partOfNameDirective = UnlinkedPartOfNameDirective(
+ name: libraryName.name,
+ nameRange: UnlinkedSourceRange(
+ offset: libraryName.offset,
+ length: libraryName.length,
+ ),
+ );
+ } else if (uri != null) {
+ final uriStr = uri.stringValue;
+ if (uriStr != null) {
+ partOfUriDirective = UnlinkedPartOfUriDirective(
+ uri: uriStr,
+ uriRange: UnlinkedSourceRange(
+ offset: uri.offset,
+ length: uri.length,
+ ),
+ );
+ }
+ }
}
}
for (var declaration in unit.declarations) {
@@ -634,15 +675,15 @@
return UnlinkedUnit(
apiSignature: Uint8List.fromList(computeUnlinkedApiSignature(unit)),
exports: exports,
- hasLibraryDirective: hasLibraryDirective,
- hasPartOfDirective: hasPartOfDirective,
imports: imports,
informativeBytes: writeUnitInformative(unit),
+ libraryAugmentationDirective: libraryAugmentationDirective,
+ libraryDirective: libraryDirective,
lineStarts: Uint32List.fromList(unit.lineInfo.lineStarts),
macroClasses: macroClasses,
- partOfName: null,
- partOfUri: null,
parts: parts,
+ partOfNameDirective: partOfNameDirective,
+ partOfUriDirective: partOfUriDirective,
);
}
diff --git a/pkg/analyzer/lib/src/dart/analysis/results.dart b/pkg/analyzer/lib/src/dart/analysis/results.dart
index 0c957ae..cef3e18 100644
--- a/pkg/analyzer/lib/src/dart/analysis/results.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/results.dart
@@ -139,6 +139,15 @@
LineInfo get lineInfo => unit.lineInfo;
}
+class PartWithoutLibraryResultImpl implements PartWithoutLibraryResult {
+ @override
+ final String path;
+
+ PartWithoutLibraryResultImpl({
+ required this.path,
+ });
+}
+
class ResolvedForCompletionResultImpl {
final AnalysisSession analysisSession;
final String path;
diff --git a/pkg/analyzer/lib/src/dart/analysis/unlinked_data.dart b/pkg/analyzer/lib/src/dart/analysis/unlinked_data.dart
index 88cfdb8..e4b4773 100644
--- a/pkg/analyzer/lib/src/dart/analysis/unlinked_data.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/unlinked_data.dart
@@ -90,6 +90,50 @@
}
}
+class UnlinkedLibraryAugmentationDirective {
+ final String uri;
+ final UnlinkedSourceRange uriRange;
+
+ UnlinkedLibraryAugmentationDirective({
+ required this.uri,
+ required this.uriRange,
+ });
+
+ factory UnlinkedLibraryAugmentationDirective.read(
+ SummaryDataReader reader,
+ ) {
+ return UnlinkedLibraryAugmentationDirective(
+ uri: reader.readStringUtf8(),
+ uriRange: UnlinkedSourceRange.read(reader),
+ );
+ }
+
+ void write(BufferedSink sink) {
+ sink.writeStringUtf8(uri);
+ uriRange.write(sink);
+ }
+}
+
+class UnlinkedLibraryDirective {
+ final String name;
+
+ UnlinkedLibraryDirective({
+ required this.name,
+ });
+
+ factory UnlinkedLibraryDirective.read(
+ SummaryDataReader reader,
+ ) {
+ return UnlinkedLibraryDirective(
+ name: reader.readStringUtf8(),
+ );
+ }
+
+ void write(BufferedSink sink) {
+ sink.writeStringUtf8(name);
+ }
+}
+
/// Unlinked information about a namespace directive.
class UnlinkedNamespaceDirective {
/// The configurations that control which library will actually be used.
@@ -159,6 +203,81 @@
}
}
+class UnlinkedPartOfNameDirective {
+ final String name;
+ final UnlinkedSourceRange nameRange;
+
+ UnlinkedPartOfNameDirective({
+ required this.name,
+ required this.nameRange,
+ });
+
+ factory UnlinkedPartOfNameDirective.read(
+ SummaryDataReader reader,
+ ) {
+ return UnlinkedPartOfNameDirective(
+ name: reader.readStringUtf8(),
+ nameRange: UnlinkedSourceRange.read(reader),
+ );
+ }
+
+ void write(BufferedSink sink) {
+ sink.writeStringUtf8(name);
+ nameRange.write(sink);
+ }
+}
+
+class UnlinkedPartOfUriDirective {
+ final String uri;
+ final UnlinkedSourceRange uriRange;
+
+ UnlinkedPartOfUriDirective({
+ required this.uri,
+ required this.uriRange,
+ });
+
+ factory UnlinkedPartOfUriDirective.read(
+ SummaryDataReader reader,
+ ) {
+ return UnlinkedPartOfUriDirective(
+ uri: reader.readStringUtf8(),
+ uriRange: UnlinkedSourceRange.read(reader),
+ );
+ }
+
+ void write(BufferedSink sink) {
+ sink.writeStringUtf8(uri);
+ uriRange.write(sink);
+ }
+}
+
+class UnlinkedSourceRange {
+ final int offset;
+ final int length;
+
+ UnlinkedSourceRange({
+ required this.offset,
+ required this.length,
+ }) {
+ RangeError.checkNotNegative(offset);
+ RangeError.checkNotNegative(length);
+ }
+
+ factory UnlinkedSourceRange.read(
+ SummaryDataReader reader,
+ ) {
+ return UnlinkedSourceRange(
+ offset: reader.readUInt30(),
+ length: reader.readUInt30(),
+ );
+ }
+
+ void write(BufferedSink sink) {
+ sink.writeUInt30(offset);
+ sink.writeUInt30(length);
+ }
+}
+
/// Unlinked information about a compilation unit.
class UnlinkedUnit {
/// The MD5 hash signature of the API portion of this unit. It depends on all
@@ -169,45 +288,45 @@
/// URIs of `export` directives.
final List<UnlinkedNamespaceDirective> exports;
- /// Is `true` if the unit contains a `library` directive.
- final bool hasLibraryDirective;
-
- /// Is `true` if the unit contains a `part of` directive.
- final bool hasPartOfDirective;
-
/// URIs of `import` directives.
final List<UnlinkedNamespaceDirective> imports;
/// Encoded informative data.
final Uint8List informativeBytes;
+ /// The `library augment 'uri';` directive.
+ final UnlinkedLibraryAugmentationDirective? libraryAugmentationDirective;
+
+ /// The `library name;` directive.
+ final UnlinkedLibraryDirective? libraryDirective;
+
/// Offsets of the first character of each line in the source code.
final Uint32List lineStarts;
/// The list of `macro` classes.
final List<MacroClass> macroClasses;
- /// The library name of the `part of my.name;` directive.
- final String? partOfName;
-
- /// URI of the `part of 'uri';` directive.
- final String? partOfUri;
-
/// URIs of `part` directives.
final List<String> parts;
+ /// The `part of my.name';` directive.
+ final UnlinkedPartOfNameDirective? partOfNameDirective;
+
+ /// The `part of 'uri';` directive.
+ final UnlinkedPartOfUriDirective? partOfUriDirective;
+
UnlinkedUnit({
required this.apiSignature,
required this.exports,
- required this.hasLibraryDirective,
- required this.hasPartOfDirective,
required this.imports,
required this.informativeBytes,
+ required this.libraryAugmentationDirective,
+ required this.libraryDirective,
required this.lineStarts,
required this.macroClasses,
- required this.partOfName,
- required this.partOfUri,
required this.parts,
+ required this.partOfNameDirective,
+ required this.partOfUriDirective,
});
factory UnlinkedUnit.read(SummaryDataReader reader) {
@@ -216,19 +335,27 @@
exports: reader.readTypedList(
() => UnlinkedNamespaceDirective.read(reader),
),
- hasLibraryDirective: reader.readBool(),
- hasPartOfDirective: reader.readBool(),
imports: reader.readTypedList(
() => UnlinkedNamespaceDirective.read(reader),
),
informativeBytes: reader.readUint8List(),
+ libraryAugmentationDirective: reader.readOptionalObject(
+ UnlinkedLibraryAugmentationDirective.read,
+ ),
+ libraryDirective: reader.readOptionalObject(
+ UnlinkedLibraryDirective.read,
+ ),
lineStarts: reader.readUInt30List(),
macroClasses: reader.readTypedList(
() => MacroClass.read(reader),
),
- partOfName: reader.readOptionalStringUtf8(),
- partOfUri: reader.readOptionalStringUtf8(),
parts: reader.readStringUtf8List(),
+ partOfNameDirective: reader.readOptionalObject(
+ UnlinkedPartOfNameDirective.read,
+ ),
+ partOfUriDirective: reader.readOptionalObject(
+ UnlinkedPartOfUriDirective.read,
+ ),
);
}
@@ -237,18 +364,30 @@
sink.writeList<UnlinkedNamespaceDirective>(exports, (x) {
x.write(sink);
});
- sink.writeBool(hasLibraryDirective);
- sink.writeBool(hasPartOfDirective);
sink.writeList<UnlinkedNamespaceDirective>(imports, (x) {
x.write(sink);
});
sink.writeUint8List(informativeBytes);
+ sink.writeOptionalObject<UnlinkedLibraryAugmentationDirective>(
+ libraryAugmentationDirective,
+ (x) => x.write(sink),
+ );
+ sink.writeOptionalObject<UnlinkedLibraryDirective>(
+ libraryDirective,
+ (x) => x.write(sink),
+ );
sink.writeUint30List(lineStarts);
sink.writeList<MacroClass>(macroClasses, (x) {
x.write(sink);
});
- sink.writeOptionalStringUtf8(partOfName);
- sink.writeOptionalStringUtf8(partOfUri);
sink.writeStringUtf8Iterable(parts);
+ sink.writeOptionalObject<UnlinkedPartOfNameDirective>(
+ partOfNameDirective,
+ (x) => x.write(sink),
+ );
+ sink.writeOptionalObject<UnlinkedPartOfUriDirective>(
+ partOfUriDirective,
+ (x) => x.write(sink),
+ );
}
}
diff --git a/pkg/analyzer/lib/src/dart/micro/library_graph.dart b/pkg/analyzer/lib/src/dart/micro/library_graph.dart
index b36a098..0f722d7 100644
--- a/pkg/analyzer/lib/src/dart/micro/library_graph.dart
+++ b/pkg/analyzer/lib/src/dart/micro/library_graph.dart
@@ -99,6 +99,16 @@
bool get exists => _unlinked.exists;
+ /// Return `true` if the file does not have a `library` directive, and has a
+ /// `part of` directive, so is probably a part.
+ bool get isPart {
+ if (unlinkedUnit.libraryDirective != null) {
+ return false;
+ }
+ return unlinkedUnit.partOfNameDirective != null ||
+ unlinkedUnit.partOfUriDirective != null;
+ }
+
/// Return the [LibraryCycle] this file belongs to, even if it consists of
/// just this file. If the library cycle is not known yet, compute it.
LibraryCycle get libraryCycle {
@@ -799,7 +809,7 @@
var performance = OperationPerformanceImpl('<root>');
- var libraryName = unlinked.unit.partOfName;
+ var libraryName = unlinked.unit.partOfNameDirective?.name;
if (libraryName != null) {
location._fsState.testView.partsDiscoveredLibraries.add(location.path);
return _partOfLibrary = location._findPartOfNameLibrary(
@@ -807,15 +817,16 @@
);
}
- var libraryUri = unlinked.unit.partOfUri;
- if (libraryUri == null) {
- return null;
+ var libraryUri = unlinked.unit.partOfUriDirective?.uri;
+ if (libraryUri != null) {
+ location._fsState.testView.partsDiscoveredLibraries.add(location.path);
+ return _partOfLibrary = location._fileForRelativeUri(
+ relativeUri: libraryUri,
+ performance: performance,
+ );
}
- location._fsState.testView.partsDiscoveredLibraries.add(location.path);
- return _partOfLibrary = location._fileForRelativeUri(
- relativeUri: libraryUri,
- performance: performance,
- );
+
+ return null;
}
void _prefetchDirectReferences() {
@@ -889,14 +900,14 @@
}
static CiderUnlinkedUnit serializeAstCiderUnlinked(CompilationUnit unit) {
+ UnlinkedLibraryDirective? libraryDirective;
+ UnlinkedLibraryAugmentationDirective? libraryAugmentationDirective;
+ UnlinkedPartOfNameDirective? partOfNameDirective;
+ UnlinkedPartOfUriDirective? partOfUriDirective;
var exports = <UnlinkedNamespaceDirective>[];
var imports = <UnlinkedNamespaceDirective>[];
var parts = <String>[];
var hasDartCoreImport = false;
- var hasLibraryDirective = false;
- var hasPartOfDirective = false;
- String? partOfName;
- String? partOfUriStr;
for (var directive in unit.directives) {
if (directive is ExportDirective) {
var builder = _serializeNamespaceDirective(directive);
@@ -907,19 +918,47 @@
if (builder.uri == 'dart:core') {
hasDartCoreImport = true;
}
+ } else if (directive is LibraryAugmentationDirective) {
+ final uri = directive.uri;
+ final uriStr = uri.stringValue;
+ if (uriStr != null) {
+ libraryAugmentationDirective = UnlinkedLibraryAugmentationDirective(
+ uri: uriStr,
+ uriRange: UnlinkedSourceRange(
+ offset: uri.offset,
+ length: uri.length,
+ ),
+ );
+ }
} else if (directive is LibraryDirective) {
- hasLibraryDirective = true;
+ libraryDirective = UnlinkedLibraryDirective(
+ name: directive.name.components.map((e) => e.name).join('.'),
+ );
} else if (directive is PartDirective) {
var uriStr = directive.uri.stringValue;
parts.add(uriStr ?? '');
} else if (directive is PartOfDirective) {
- hasPartOfDirective = true;
- var libraryName = directive.libraryName;
- var uriStr = directive.uri?.stringValue;
+ final libraryName = directive.libraryName;
+ final uri = directive.uri;
if (libraryName != null) {
- partOfName = libraryName.components.map((e) => e.name).join('.');
- } else if (uriStr != null) {
- partOfUriStr = uriStr;
+ partOfNameDirective = UnlinkedPartOfNameDirective(
+ name: libraryName.name,
+ nameRange: UnlinkedSourceRange(
+ offset: libraryName.offset,
+ length: libraryName.length,
+ ),
+ );
+ } else if (uri != null) {
+ final uriStr = uri.stringValue;
+ if (uriStr != null) {
+ partOfUriDirective = UnlinkedPartOfUriDirective(
+ uri: uriStr,
+ uriRange: UnlinkedSourceRange(
+ offset: uri.offset,
+ length: uri.length,
+ ),
+ );
+ }
}
}
}
@@ -957,15 +996,15 @@
var unlinkedUnit = UnlinkedUnit(
apiSignature: computeUnlinkedApiSignature(unit),
exports: exports,
- hasLibraryDirective: hasLibraryDirective,
- hasPartOfDirective: hasPartOfDirective,
imports: imports,
informativeBytes: writeUnitInformative(unit),
+ libraryAugmentationDirective: libraryAugmentationDirective,
+ libraryDirective: libraryDirective,
lineStarts: Uint32List.fromList(unit.lineInfo.lineStarts),
macroClasses: [],
- partOfName: partOfName,
- partOfUri: partOfUriStr,
parts: parts,
+ partOfNameDirective: partOfNameDirective,
+ partOfUriDirective: partOfUriDirective,
);
return CiderUnlinkedUnit(
diff --git a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
index efb1059..592bb38 100644
--- a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
+++ b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
@@ -579,7 +579,7 @@
file.exists,
file.getContent(),
file.lineInfo,
- file.unlinkedUnit.hasPartOfDirective,
+ file.isPart,
fileResult.unit,
fileResult.errors,
);
diff --git a/pkg/analyzer/lib/src/summary2/data_reader.dart b/pkg/analyzer/lib/src/summary2/data_reader.dart
index 9c1988d..c5798ee 100644
--- a/pkg/analyzer/lib/src/summary2/data_reader.dart
+++ b/pkg/analyzer/lib/src/summary2/data_reader.dart
@@ -54,6 +54,14 @@
return _doubleBuffer[0];
}
+ T? readOptionalObject<T>(T Function(SummaryDataReader reader) read) {
+ if (readBool()) {
+ return read(this);
+ } else {
+ return null;
+ }
+ }
+
String? readOptionalStringReference() {
if (readBool()) {
return readStringReference();
diff --git a/pkg/analyzer/lib/src/summary2/data_writer.dart b/pkg/analyzer/lib/src/summary2/data_writer.dart
index 3f560a8..ede7d8b 100644
--- a/pkg/analyzer/lib/src/summary2/data_writer.dart
+++ b/pkg/analyzer/lib/src/summary2/data_writer.dart
@@ -137,6 +137,15 @@
}
}
+ void writeOptionalObject<T>(T? object, void Function(T x) write) {
+ if (object != null) {
+ writeBool(true);
+ write(object);
+ } else {
+ writeBool(false);
+ }
+ }
+
void writeOptionalStringUtf8(String? value) {
if (value != null) {
writeBool(true);
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index 4d58c07..5f260ff 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -6019,6 +6019,7 @@
implicitly uses the same version as the defining compilation unit:
```dart
+ %uri="lib/part.dart"
part of 'test.dart';
```
@@ -10939,6 +10940,7 @@
by URI:
```dart
+ %uri="lib/part_file.dart"
part of 'test.dart';
```
POSITIONAL_SUPER_FORMAL_PARAMETER_WITH_POSITIONAL_ARGUMENT:
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
index 870d899..82158be 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_resolution_test.dart
@@ -270,15 +270,20 @@
}
test_annotation_onDirective_partOf() async {
- newFile('$testPackageLibPath/a.dart', r'''
+ final a = newFile('$testPackageLibPath/a.dart', r'''
part 'test.dart';
''');
+
addTestFile(r'''
@a
part of 'a.dart';
const a = 1;
''');
+
+ // Make sure that the part knows its library.
+ contextFor(a.path).currentSession.getParsedUnit(a.path);
+
await resolveTestFile();
var directive = findNode.partOf('a.dart');
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
index 60fd9f7..5a963a6 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
@@ -2734,21 +2734,15 @@
}
test_part_getResult_noLibrary() async {
- var c = convertPath('/test/lib/c.dart');
- newFile(c, r'''
+ final c = newFile('/test/lib/c.dart', r'''
part of a;
class C {}
-var a = new A();
-var b = new B();
''');
- driver.addFile(c);
-
- // There is no library which c.dart is a part of, so it has unresolved
- // A and B references.
- ResolvedUnitResult result = await driver.getResultValid(c);
- expect(result.errors, isNotEmpty);
- expect(result.unit, isNotNull);
+ // There is no library which c.dart is a part of, so invalid result.
+ final result = await driver.getResult(c.path);
+ result as PartWithoutLibraryResult;
+ expect(result.path, c.path);
}
test_part_getUnitElement_afterLibrary() async {
@@ -2829,28 +2823,14 @@
}
test_part_getUnitElement_noLibrary() async {
- var c = convertPath('/test/lib/c.dart');
- newFile(c, r'''
+ final c = newFile('/test/lib/c.dart', r'''
part of a;
-var a = new A();
-var b = new B();
''');
- driver.addFile(c);
-
- // We don't know the library of c.dart, but we should get a result.
- // The types "A" and "B" are unresolved.
- {
- var result = await driver.getUnitElement(c);
- result as UnitElementResult;
- var partUnit = result.element;
-
- expect(partUnit.topLevelVariables[0].name, 'a');
- assertType(partUnit.topLevelVariables[0].type, 'dynamic');
-
- expect(partUnit.topLevelVariables[1].name, 'b');
- assertType(partUnit.topLevelVariables[1].type, 'dynamic');
- }
+ // We don't know the library of c.dart, so invalid result.
+ var result = await driver.getUnitElement(c.path);
+ result as PartWithoutLibraryResult;
+ expect(result.path, c.path);
}
test_part_results_afterLibrary() async {
@@ -2889,15 +2869,16 @@
// Update a.dart so that c.dart is not a part.
{
+ allResults.clear();
+
modifyFile(a, '// does not use c.dart anymore');
driver.changeFile(a);
await waitForIdleWithoutExceptions();
- // Now c.dart does not have a library context, so A and B cannot be
- // resolved, so there are errors.
- var result =
- allResults.whereType<ErrorsResult>().lastWhere((r) => r.path == c);
- expect(result.errors, isNotEmpty);
+ // Now c.dart does not know the library, so invalid result.
+ allResults
+ .whereType<PartWithoutLibraryResult>()
+ .lastWhere((r) => r.path == c);
}
}
@@ -2949,11 +2930,29 @@
await waitForIdleWithoutExceptions();
- // There is no library which c.dart is a part of, so it has unresolved
- // A and B references.
- var result =
- allResults.whereType<ErrorsResult>().lastWhere((r) => r.path == c);
- expect(result.errors, isNotEmpty);
+ // We don't know the library for `c.dart`, so report an invalid result.
+ allResults
+ .whereType<PartWithoutLibraryResult>()
+ .lastWhere((result) => result.path == c);
+ }
+
+ test_part_results_noLibrary_priority() async {
+ var c = newFile('/test/lib/c.dart', r'''
+part of a;
+class C {}
+var a = new A();
+var b = new B();
+''');
+
+ driver.addFile(c.path);
+ driver.priorityFiles = [c.path];
+
+ await waitForIdleWithoutExceptions();
+
+ // We don't know the library for `c.dart`, so report an invalid result.
+ allResults
+ .whereType<PartWithoutLibraryResult>()
+ .lastWhere((result) => result.path == c.path);
}
test_part_results_priority_beforeLibrary() async {
diff --git a/pkg/analyzer/test/src/dart/analysis/search_test.dart b/pkg/analyzer/test/src/dart/analysis/search_test.dart
index ba431f2..490c069 100644
--- a/pkg/analyzer/test/src/dart/analysis/search_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/search_test.dart
@@ -2526,24 +2526,6 @@
expect(c.id, endsWith('c.dart;C'));
}
- test_subtypes_class_partWithoutLibrary() async {
- await resolveTestCode('''
-part of lib;
-
-class A {}
-class B extends A {}
-''');
- var a = findElement.class_('A');
-
- List<SubtypeResult> subtypes =
- await driver.search.subtypes(SearchedFiles(), type: a);
- expect(subtypes, hasLength(1));
-
- SubtypeResult b = subtypes.singleWhere((r) => r.name == 'B');
- expect(b.libraryUri, testUriStr);
- expect(b.id, '$testUriStr;$testUriStr;B');
- }
-
test_subtypes_enum() async {
await resolveTestCode('''
class A {}
diff --git a/pkg/analyzer/test/src/diagnostics/sdk_version_async_exported_from_core_test.dart b/pkg/analyzer/test/src/diagnostics/sdk_version_async_exported_from_core_test.dart
index 90054d2..479a695 100644
--- a/pkg/analyzer/test/src/diagnostics/sdk_version_async_exported_from_core_test.dart
+++ b/pkg/analyzer/test/src/diagnostics/sdk_version_async_exported_from_core_test.dart
@@ -2,9 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
+import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/src/dart/error/hint_codes.dart';
+import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
+import '../dart/resolution/context_collection_resolution.dart';
import 'sdk_constraint_verifier_support.dart';
main() {
@@ -49,14 +52,31 @@
}
test_equals_implicitImportOfCore_inPart() async {
- newFile('/lib.dart', '''
+ writeTestPackagePubspecYamlFile(
+ PubspecYamlFileConfig(
+ sdkVersion: '>=2.1.0',
+ ),
+ );
+
+ final lib = newFile('$testPackageLibPath/lib.dart', '''
library lib;
+
+part 'a.dart';
''');
- await verifyVersion('2.1.0', '''
+
+ final a = newFile('$testPackageLibPath/a.dart', r'''
part of lib;
Future<int> zero() async => 0;
''');
+
+ final analysisSession = contextFor(lib.path).currentSession;
+ final resolvedLibrary = await analysisSession.getResolvedLibrary(lib.path);
+ resolvedLibrary as ResolvedLibraryResult;
+
+ final resolvedPart = resolvedLibrary.units.last;
+ expect(resolvedPart.path, a.path);
+ assertErrorsInList(resolvedPart.errors, []);
}
test_lessThan_explicitImportOfAsync() async {
@@ -97,14 +117,31 @@
}
test_lessThan_implicitImportOfCore_inPart() async {
- newFile('/lib.dart', '''
+ writeTestPackagePubspecYamlFile(
+ PubspecYamlFileConfig(
+ sdkVersion: '>=2.0.0',
+ ),
+ );
+
+ final lib = newFile('$testPackageLibPath/lib.dart', '''
library lib;
+
+part 'a.dart';
''');
- await verifyVersion('2.0.0', '''
+
+ final a = newFile('$testPackageLibPath/a.dart', r'''
part of lib;
Future<int> zero() async => 0;
-''', expectedErrors: [
+''');
+
+ final analysisSession = contextFor(lib.path).currentSession;
+ final resolvedLibrary = await analysisSession.getResolvedLibrary(lib.path);
+ resolvedLibrary as ResolvedLibraryResult;
+
+ final resolvedPart = resolvedLibrary.units.last;
+ expect(resolvedPart.path, a.path);
+ assertErrorsInList(resolvedPart.errors, [
error(HintCode.SDK_VERSION_ASYNC_EXPORTED_FROM_CORE, 14, 6),
]);
}
diff --git a/pkg/analyzer_plugin/test/utilities/completion/type_member_contributor_test.dart b/pkg/analyzer_plugin/test/utilities/completion/type_member_contributor_test.dart
index 3c42768..f4b9318 100644
--- a/pkg/analyzer_plugin/test/utilities/completion/type_member_contributor_test.dart
+++ b/pkg/analyzer_plugin/test/utilities/completion/type_member_contributor_test.dart
@@ -3068,16 +3068,17 @@
int T1;
F1() { }
class X {X.c(); X._d(); z() {}}''');
- addSource('/home/test/lib/a.dart', '''
+ final a = newFile('/home/test/lib/a.dart', '''
library libA;
import 'b.dart';
- part "$testFile";
+ part 'test.dart';
class A { }
var m;''');
addTestSource('''
part of libA;
class B { B.bar(int x); }
main() {new ^}''');
+ await resolveFile(a.path);
await computeSuggestions();
expect(replacementOffset, completionOffset);
expect(replacementLength, 0);
diff --git a/pkg/compiler/lib/src/constants/values.dart b/pkg/compiler/lib/src/constants/values.dart
index b12d2da..07fc1d5 100644
--- a/pkg/compiler/lib/src/constants/values.dart
+++ b/pkg/compiler/lib/src/constants/values.dart
@@ -86,6 +86,7 @@
List<ConstantValue> getDependencies();
+ // TODO(48820): Add type parameters.
accept(ConstantValueVisitor visitor, arg);
/// The value of this constant in Dart syntax, if possible.
diff --git a/pkg/compiler/lib/src/js/rewrite_async.dart b/pkg/compiler/lib/src/js/rewrite_async.dart
index 7cc6ec9..82d1662 100644
--- a/pkg/compiler/lib/src/js/rewrite_async.dart
+++ b/pkg/compiler/lib/src/js/rewrite_async.dart
@@ -9,7 +9,7 @@
import 'dart:collection';
import 'dart:math' show max;
-import 'package:js_runtime/shared/async_await_error_codes.dart' as error_codes;
+import 'package:js_runtime/synced/async_await_error_codes.dart' as error_codes;
import '../common.dart';
import '../io/source_information.dart' show SourceInformation;
diff --git a/pkg/compiler/lib/src/js_backend/backend_usage.dart b/pkg/compiler/lib/src/js_backend/backend_usage.dart
index 7e08bd6..37ef534 100644
--- a/pkg/compiler/lib/src/js_backend/backend_usage.dart
+++ b/pkg/compiler/lib/src/js_backend/backend_usage.dart
@@ -161,7 +161,8 @@
if (_isValidEntity(element)) return true;
SourceSpan span = _frontendStrategy.spanFromSpannable(element, element);
if (library.canonicalUri.isScheme('dart') &&
- span.uri.path.contains('_internal/js_runtime/lib/')) {
+ (span.uri.path.contains('_internal/js_runtime/lib') ||
+ span.uri.path.contains('_internal/js_shared/lib'))) {
// TODO(johnniwinther): We should be more precise about these.
return true;
} else {
diff --git a/pkg/compiler/lib/src/js_backend/namer.dart b/pkg/compiler/lib/src/js_backend/namer.dart
index 3f90fc2..392e4e5 100644
--- a/pkg/compiler/lib/src/js_backend/namer.dart
+++ b/pkg/compiler/lib/src/js_backend/namer.dart
@@ -9,7 +9,7 @@
import 'package:front_end/src/api_unstable/dart2js.dart'
show $0, $9, $A, $Z, $_, $a, $g, $s, $z;
-import 'package:js_runtime/shared/embedded_names.dart' show JsGetName;
+import 'package:js_runtime/synced/embedded_names.dart' show JsGetName;
import '../closure.dart';
import '../common.dart';
diff --git a/pkg/compiler/lib/src/js_backend/runtime_types_new.dart b/pkg/compiler/lib/src/js_backend/runtime_types_new.dart
index 2f8816e..a0f4161 100644
--- a/pkg/compiler/lib/src/js_backend/runtime_types_new.dart
+++ b/pkg/compiler/lib/src/js_backend/runtime_types_new.dart
@@ -6,7 +6,7 @@
library js_backend.runtime_types_new;
-import 'package:js_runtime/shared/recipe_syntax.dart';
+import 'package:js_shared/synced/recipe_syntax.dart';
import '../common/elements.dart' show CommonElements, JCommonElements;
import '../elements/entities.dart';
diff --git a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
index 78a6912..0e14253 100644
--- a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
@@ -6,7 +6,7 @@
library dart2js.js_emitter.class_stub_generator;
-import 'package:js_runtime/shared/embedded_names.dart'
+import 'package:js_runtime/synced/embedded_names.dart'
show TearOffParametersPropertyNames;
import '../common/elements.dart' show CommonElements;
diff --git a/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart b/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart
index 1cbf7e1..5932c85 100644
--- a/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart
+++ b/pkg/compiler/lib/src/js_emitter/code_emitter_task.dart
@@ -68,7 +68,7 @@
return _nativeEmitter;
}
- Emitter get emitter {
+ Emitter /*!*/ get emitter {
assert(_emitter != null,
failedAt(NO_LOCATION_SPANNABLE, "Emitter has not been created yet."));
return _emitter;
diff --git a/pkg/compiler/lib/src/js_emitter/constant_ordering.dart b/pkg/compiler/lib/src/js_emitter/constant_ordering.dart
index ed04b1c..3103cb2 100644
--- a/pkg/compiler/lib/src/js_emitter/constant_ordering.dart
+++ b/pkg/compiler/lib/src/js_emitter/constant_ordering.dart
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-// @dart = 2.10
-
library dart2js.js_emitter.constant_ordering;
import '../constants/values.dart';
@@ -22,7 +20,7 @@
class _ConstantOrdering
implements ConstantOrdering, ConstantValueVisitor<int, ConstantValue> {
final Sorter _sorter;
- _DartTypeOrdering _dartTypeOrdering;
+ late _DartTypeOrdering _dartTypeOrdering;
_ConstantOrdering(this._sorter) {
_dartTypeOrdering = _DartTypeOrdering(this);
}
@@ -37,7 +35,7 @@
return a.accept(this, b);
}
- static int compareLists<S, T>(int compare(S a, T b), List<S> a, List<T> b) {
+ static int compareLists<T>(int compare(T a, T b), List<T> a, List<T> b) {
int r = a.length.compareTo(b.length);
if (r != 0) return r;
for (int i = 0; i < a.length; i++) {
@@ -54,7 +52,7 @@
}
int compareMembers(MemberEntity a, MemberEntity b) {
- int r = a.name.compareTo(b.name);
+ int r = a.name!.compareTo(b.name!);
if (r != 0) return r;
return _sorter.compareMembersByLocation(a, b);
}
@@ -139,8 +137,8 @@
return compareLists(
compareValues,
- aFields.map((field) => a.fields[field]).toList(),
- aFields.map((field) => b.fields[field]).toList());
+ aFields.map((field) => a.fields[field]!).toList(),
+ aFields.map((field) => b.fields[field]!).toList());
}
@override
@@ -184,7 +182,8 @@
DeferredGlobalConstantValue a, DeferredGlobalConstantValue b) {
int r = compareValues(a.referenced, b.referenced);
if (r != 0) return r;
- return a.unit.compareTo(b.unit);
+ // TODO(48820): Should unit be non-nullable?
+ return a.unit!.compareTo(b.unit!);
}
@override
@@ -234,7 +233,7 @@
class _DartTypeOrdering extends DartTypeVisitor<int, DartType> {
final _ConstantOrdering _constantOrdering;
- DartType _root;
+ DartType? _root;
final List<FunctionTypeVariable> _leftFunctionTypeVariables = [];
final List<FunctionTypeVariable> _rightFunctionTypeVariables = [];
_DartTypeOrdering(this._constantOrdering);
diff --git a/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
index 4d5beaf..5251365 100644
--- a/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/interceptor_stub_generator.dart
@@ -6,7 +6,7 @@
library dart2js.js_emitter.interceptor_stub_generator;
-import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
+import 'package:js_runtime/synced/embedded_names.dart' as embeddedNames;
import '../common/elements.dart';
import '../constants/values.dart';
@@ -420,7 +420,7 @@
CustomElementsCodegenAnalysis analysis = _customElementsCodegenAnalysis;
if (!analysis.needsTable) return null;
- List<jsAst.Expression> elements = [];
+ List<jsAst.Expression /*!*/ > elements = [];
Iterable<ConstantValue> constants =
_codegenWorld.getConstantsForEmission(_emitter.compareConstants);
for (ConstantValue constant in constants) {
diff --git a/pkg/compiler/lib/src/js_emitter/main_call_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/main_call_stub_generator.dart
index 6098493..c6af592 100644
--- a/pkg/compiler/lib/src/js_emitter/main_call_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/main_call_stub_generator.dart
@@ -7,7 +7,7 @@
library dart2js.js_emitter.main_call_stub_generator;
import 'package:compiler/src/options.dart';
-import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
+import 'package:js_runtime/synced/embedded_names.dart' as embeddedNames;
import '../common/elements.dart';
import '../elements/entities.dart';
diff --git a/pkg/compiler/lib/src/js_emitter/native_generator.dart b/pkg/compiler/lib/src/js_emitter/native_generator.dart
index 71e6414..a47b6be 100644
--- a/pkg/compiler/lib/src/js_emitter/native_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/native_generator.dart
@@ -6,7 +6,7 @@
library dart2js.js_emitter.native_generator;
-import 'package:js_runtime/shared/embedded_names.dart' as embeddedNames;
+import 'package:js_runtime/synced/embedded_names.dart' as embeddedNames;
import '../js/js.dart' as jsAst;
import '../js/js.dart' show js;
diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
index f0ca9812..9ff95c5 100644
--- a/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart
@@ -8,7 +8,7 @@
import 'dart:convert' show JsonEncoder;
-import 'package:js_runtime/shared/embedded_names.dart'
+import 'package:js_runtime/synced/embedded_names.dart'
show
ARRAY_RTI_PROPERTY,
DEFERRED_INITIALIZED,
diff --git a/pkg/compiler/lib/src/kernel/element_map_impl.dart b/pkg/compiler/lib/src/kernel/element_map_impl.dart
index 476b906..f28ab293 100644
--- a/pkg/compiler/lib/src/kernel/element_map_impl.dart
+++ b/pkg/compiler/lib/src/kernel/element_map_impl.dart
@@ -6,7 +6,7 @@
import 'package:front_end/src/api_prototype/constant_evaluator.dart' as ir;
import 'package:front_end/src/api_unstable/dart2js.dart' as ir;
-import 'package:js_runtime/shared/embedded_names.dart';
+import 'package:js_runtime/synced/embedded_names.dart';
import 'package:kernel/ast.dart' as ir;
import 'package:kernel/class_hierarchy.dart' as ir;
import 'package:kernel/core_types.dart' as ir;
diff --git a/pkg/compiler/lib/src/ssa/builder.dart b/pkg/compiler/lib/src/ssa/builder.dart
index 8721f91..cc26197 100644
--- a/pkg/compiler/lib/src/ssa/builder.dart
+++ b/pkg/compiler/lib/src/ssa/builder.dart
@@ -4,7 +4,7 @@
// @dart = 2.10
-import 'package:js_runtime/shared/embedded_names.dart';
+import 'package:js_runtime/synced/embedded_names.dart';
import 'package:kernel/ast.dart' as ir;
import '../closure.dart';
diff --git a/pkg/compiler/lib/src/universe/codegen_world_builder.dart b/pkg/compiler/lib/src/universe/codegen_world_builder.dart
index 710e2c4..73a25f6 100644
--- a/pkg/compiler/lib/src/universe/codegen_world_builder.dart
+++ b/pkg/compiler/lib/src/universe/codegen_world_builder.dart
@@ -81,10 +81,10 @@
void forEachStaticField(void Function(FieldEntity) f);
/// Returns the types that are live as constant type literals.
- Iterable<DartType> get constTypeLiterals;
+ Iterable<DartType /*!*/ > get constTypeLiterals;
/// Returns the types that are live as constant type arguments.
- Iterable<DartType> get liveTypeArguments;
+ Iterable<DartType /*!*/ > get liveTypeArguments;
/// Returns a list of constants topologically sorted so that dependencies
/// appear before the dependent constant.
diff --git a/pkg/compiler/lib/src/universe/use.dart b/pkg/compiler/lib/src/universe/use.dart
index 9ddd60d..2adead4 100644
--- a/pkg/compiler/lib/src/universe/use.dart
+++ b/pkg/compiler/lib/src/universe/use.dart
@@ -899,7 +899,7 @@
class ConstantUse {
static const String tag = 'constant-use';
- final ConstantValue value;
+ final ConstantValue /*!*/ value;
ConstantUse._(this.value);
@@ -922,7 +922,7 @@
}
/// Constant used as the initial value of a field.
- ConstantUse.init(ConstantValue value) : this._(value);
+ ConstantUse.init(ConstantValue /*!*/ value) : this._(value);
/// Type constant used for registration of custom elements.
ConstantUse.customElements(TypeConstantValue value) : this._(value);
diff --git a/pkg/compiler/pubspec.yaml b/pkg/compiler/pubspec.yaml
index 22f0ac4..f3dfd26 100644
--- a/pkg/compiler/pubspec.yaml
+++ b/pkg/compiler/pubspec.yaml
@@ -17,6 +17,7 @@
front_end: any
js_ast: any
js_runtime: any
+ js_shared: any
kernel: any
dev_dependencies:
diff --git a/pkg/js_runtime/README.md b/pkg/js_runtime/README.md
index 5f60952..02f263b 100644
--- a/pkg/js_runtime/README.md
+++ b/pkg/js_runtime/README.md
@@ -3,7 +3,7 @@
This package contains code that is shared between the dart2js compiler and the
dart2js runtime libraries.
-*Important*: all code under the `lib/shared/` must be kept in sync with the
-runtime at all times (in `sdk/lib/_internal/js_runtime/lib/shared`). The
+*Important*: all code under the `lib/synced/` must be kept in sync with the
+runtime at all times (in `sdk/lib/_internal/js_runtime/lib/synced`). The
`test/in_sync_test.dart` test verifies this.
diff --git a/pkg/js_runtime/lib/shared/async_await_error_codes.dart b/pkg/js_runtime/lib/synced/async_await_error_codes.dart
similarity index 100%
rename from pkg/js_runtime/lib/shared/async_await_error_codes.dart
rename to pkg/js_runtime/lib/synced/async_await_error_codes.dart
diff --git a/pkg/js_runtime/lib/shared/embedded_names.dart b/pkg/js_runtime/lib/synced/embedded_names.dart
similarity index 100%
rename from pkg/js_runtime/lib/shared/embedded_names.dart
rename to pkg/js_runtime/lib/synced/embedded_names.dart
diff --git a/pkg/js_runtime/test/in_sync_test.dart b/pkg/js_runtime/test/in_sync_test.dart
index 4dbef635..5dab586 100644
--- a/pkg/js_runtime/test/in_sync_test.dart
+++ b/pkg/js_runtime/test/in_sync_test.dart
@@ -11,9 +11,9 @@
import 'package:expect/expect.dart';
void main(List<String> argv) {
- var packageDir = Platform.script.resolve('../lib/shared/');
+ var packageDir = Platform.script.resolve('../lib/synced/');
var sdkDir = Platform.script
- .resolve('../../../sdk/lib/_internal/js_runtime/lib/shared/');
+ .resolve('../../../sdk/lib/_internal/js_runtime/lib/synced/');
var rPackageDir =
relativizeUri(Directory.current.uri, packageDir, Platform.isWindows);
var rSdkDir =
diff --git a/pkg/js_shared/OWNERS b/pkg/js_shared/OWNERS
new file mode 100644
index 0000000..f5bd90c
--- /dev/null
+++ b/pkg/js_shared/OWNERS
@@ -0,0 +1 @@
+file:/tools/OWNERS_WEB
diff --git a/pkg/js_shared/README.md b/pkg/js_shared/README.md
new file mode 100644
index 0000000..cce9c2e
--- /dev/null
+++ b/pkg/js_shared/README.md
@@ -0,0 +1,13 @@
+# Package `js_shared`:
+
+This code is a compile time dependency of dart2js and DDC. It is imported as
+a `package:` import by both compilers.
+
+There is an exact copy in the SDK of the libraries in the
+`pkg/js_shared/lib/synced` sub-directory.
+Those libraries are imported as `dart:` imports by the dart2js and DDC runtime
+libraries.
+
+*Important*: all code under `pkg/js_shared/lib/synced` must be kept in sync with
+the runtime (in `sdk/lib/_internal/js_shared/lib/synced`) at all times. The
+`test/in_sync_test.dart` test verifies this.
diff --git a/pkg/js_runtime/lib/shared/recipe_syntax.dart b/pkg/js_shared/lib/synced/recipe_syntax.dart
similarity index 98%
rename from pkg/js_runtime/lib/shared/recipe_syntax.dart
rename to pkg/js_shared/lib/synced/recipe_syntax.dart
index 7305491..3ccec60 100644
--- a/pkg/js_runtime/lib/shared/recipe_syntax.dart
+++ b/pkg/js_shared/lib/synced/recipe_syntax.dart
@@ -6,8 +6,8 @@
/// Constants and predicates used for encoding and decoding type recipes.
///
-/// This library is shared between the compiler and the runtime system.
-library dart2js._recipe_syntax;
+/// This library is synchronized between the compiler and the runtime system.
+library js_shared._recipe_syntax;
abstract class Recipe {
Recipe._();
diff --git a/pkg/js_shared/pubspec.yaml b/pkg/js_shared/pubspec.yaml
new file mode 100644
index 0000000..6424aac
--- /dev/null
+++ b/pkg/js_shared/pubspec.yaml
@@ -0,0 +1,10 @@
+name: js_shared
+# This package is not intended for consumption on pub.dev. DO NOT publish.
+publish_to: none
+
+environment:
+ sdk: '>=2.12.0 <3.0.0'
+
+dev_dependencies:
+ expect: any
+ _fe_analyzer_shared: any
diff --git a/pkg/js_shared/test/in_sync_test.dart b/pkg/js_shared/test/in_sync_test.dart
new file mode 100644
index 0000000..e10c4d6
--- /dev/null
+++ b/pkg/js_shared/test/in_sync_test.dart
@@ -0,0 +1,37 @@
+// Copyright (c) 2022, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+/// Test to verify that this package is in-sync with shared runtime libraries.
+import 'dart:io';
+
+import 'package:_fe_analyzer_shared/src/util/relativize.dart';
+import 'package:expect/expect.dart';
+
+void main(List<String> argv) {
+ var packageDir = Platform.script.resolve('../lib/synced/');
+ var sdkDir = Platform.script
+ .resolve('../../../sdk/lib/_internal/js_shared/lib/synced/');
+ var rPackageDir =
+ relativizeUri(Directory.current.uri, packageDir, Platform.isWindows);
+ var rSdkDir =
+ relativizeUri(Directory.current.uri, sdkDir, Platform.isWindows);
+
+ for (var file in Directory.fromUri(sdkDir).listSync()) {
+ if (file is File) {
+ var filename = file.uri.pathSegments.last;
+ var packageFile = File.fromUri(packageDir.resolve(filename));
+ Expect.isTrue(
+ packageFile.existsSync(),
+ "$filename not in sync. Please update it by running:\n"
+ " cp $rSdkDir$filename $rPackageDir$filename");
+ var original = file.readAsBytesSync();
+ var copy = packageFile.readAsBytesSync();
+ Expect.listEquals(
+ original,
+ copy,
+ "$filename not in sync. Please update it by running:\n"
+ " cp $rSdkDir$filename $rPackageDir$filename");
+ }
+ }
+}
diff --git a/pkg/nnbd_migration/test/edge_builder_test.dart b/pkg/nnbd_migration/test/edge_builder_test.dart
index 8609209..e1df28b 100644
--- a/pkg/nnbd_migration/test/edge_builder_test.dart
+++ b/pkg/nnbd_migration/test/edge_builder_test.dart
@@ -5730,10 +5730,9 @@
Future<void> test_part_metadata() async {
var pathContext = resourceProvider.pathContext;
addSource(pathContext.join(pathContext.dirname(testFile), 'part.dart'), '''
-part of test;
+part of 'test.dart';
''');
await analyze('''
-library test;
@deprecated
part 'part.dart';
''');
@@ -5744,10 +5743,13 @@
Future<void> test_part_of_identifier() async {
var pathContext = resourceProvider.pathContext;
var testFileName = pathContext.basename(testFile);
- addSource(pathContext.join(pathContext.dirname(testFile), 'lib.dart'), '''
+ var libPath = pathContext.join(pathContext.dirname(testFile), 'lib.dart');
+ addSource(libPath, '''
library test;
part '$testFileName';
''');
+ // Discover the library for the part.
+ session.getParsedUnit(libPath);
await analyze('''
part of test;
''');
@@ -5758,13 +5760,16 @@
Future<void> test_part_of_metadata() async {
var pathContext = resourceProvider.pathContext;
var testFileName = pathContext.basename(testFile);
- addSource(pathContext.join(pathContext.dirname(testFile), 'lib.dart'), '''
-library test;
+ var libPath = pathContext.join(pathContext.dirname(testFile), 'lib.dart');
+ addSource(libPath, '''
part '$testFileName';
''');
+ // TODO(scheglov) This should not be necessary, we use URI, so can find it.
+ // Discover the library for the part.
+ session.getParsedUnit(libPath);
await analyze('''
@deprecated
-part of test;
+part of 'lib.dart';
''');
// No assertions needed; the AnnotationTracker mixin verifies that the
// metadata was visited.
@@ -5773,9 +5778,13 @@
Future<void> test_part_of_path() async {
var pathContext = resourceProvider.pathContext;
var testFileName = pathContext.basename(testFile);
- addSource(pathContext.join(pathContext.dirname(testFile), 'lib.dart'), '''
+ var libPath = pathContext.join(pathContext.dirname(testFile), 'lib.dart');
+ addSource(libPath, '''
part '$testFileName';
''');
+ // TODO(scheglov) This should not be necessary, we use URI, so can find it.
+ // Discover the library for the part.
+ session.getParsedUnit(libPath);
await analyze('''
part of 'lib.dart';
''');
diff --git a/pkg/pkg.status b/pkg/pkg.status
index 2aef55f..b7d1949 100644
--- a/pkg/pkg.status
+++ b/pkg/pkg.status
@@ -140,6 +140,7 @@
front_end/test/hot_reload_e2e_test: Skip
frontend_server/test/*: SkipByDesign # Only meant to run on vm
js_runtime/test/*: SkipByDesign # Only meant to run on vm
+js_shared/test/*: SkipByDesign # Only meant to run on vm
vm/test/*: SkipByDesign # Only meant to run on vm
vm_service/test/*: SkipByDesign # Uses dart:io
vm_snapshot_analysis/test/*: SkipByDesign # Only meant to run on vm
diff --git a/runtime/vm/compiler/backend/il.cc b/runtime/vm/compiler/backend/il.cc
index a6b8720..823e4a8 100644
--- a/runtime/vm/compiler/backend/il.cc
+++ b/runtime/vm/compiler/backend/il.cc
@@ -2389,21 +2389,21 @@
return left()->definition();
} else if (rhs == 0) {
return right()->definition();
- } else if (rhs == 2) {
- const int64_t shift_1 = 1;
- ConstantInstr* constant_1 =
- flow_graph->GetConstant(Smi::Handle(Smi::New(shift_1)));
+ } else if ((rhs > 0) && Utils::IsPowerOfTwo(rhs)) {
+ const int64_t shift_amount = Utils::ShiftForPowerOfTwo(rhs);
+ ConstantInstr* constant_shift_amount = flow_graph->GetConstant(
+ Smi::Handle(Smi::New(shift_amount)), representation());
BinaryIntegerOpInstr* shift = BinaryIntegerOpInstr::Make(
representation(), Token::kSHL, left()->CopyWithType(),
- new Value(constant_1), GetDeoptId(), can_overflow(),
+ new Value(constant_shift_amount), GetDeoptId(), can_overflow(),
is_truncating(), range(), SpeculativeModeOfInputs());
if (shift != nullptr) {
// Assign a range to the shift factor, just in case range
// analysis no longer runs after this rewriting.
if (auto shift_with_range = shift->AsShiftIntegerOp()) {
shift_with_range->set_shift_range(
- new Range(RangeBoundary::FromConstant(shift_1),
- RangeBoundary::FromConstant(shift_1)));
+ new Range(RangeBoundary::FromConstant(shift_amount),
+ RangeBoundary::FromConstant(shift_amount)));
}
flow_graph->InsertBefore(this, shift, env(), FlowGraph::kValue);
return shift;
diff --git a/sdk/lib/_internal/js_runtime/lib/shared/recipe_syntax.dart b/sdk/lib/_internal/js_runtime/lib/shared/recipe_syntax.dart
deleted file mode 100644
index 7305491..0000000
--- a/sdk/lib/_internal/js_runtime/lib/shared/recipe_syntax.dart
+++ /dev/null
@@ -1,239 +0,0 @@
-// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
-// for details. All rights reserved. Use of this source code is governed by a
-// BSD-style license that can be found in the LICENSE file.
-
-// @dart=2.12
-
-/// Constants and predicates used for encoding and decoding type recipes.
-///
-/// This library is shared between the compiler and the runtime system.
-library dart2js._recipe_syntax;
-
-abstract class Recipe {
- Recipe._();
-
- // Operators.
-
- static const int separator = _comma;
- static const String separatorString = _commaString;
-
- static const int toType = _semicolon;
- static const String toTypeString = _semicolonString;
-
- static const int pushErased = _hash;
- static const String pushErasedString = _hashString;
- static const int pushDynamic = _at;
- static const String pushDynamicString = _atString;
- static const int pushVoid = _tilde;
- static const String pushVoidString = _tildeString;
-
- static const int wrapStar = _asterisk;
- static const String wrapStarString = _asteriskString;
- static const int wrapQuestion = _question;
- static const String wrapQuestionString = _questionString;
- static const int wrapFutureOr = _slash;
- static const String wrapFutureOrString = _slashString;
-
- static const int startTypeArguments = _lessThan;
- static const String startTypeArgumentsString = _lessThanString;
- static const int endTypeArguments = _greaterThan;
- static const String endTypeArgumentsString = _greaterThanString;
-
- static const int startFunctionArguments = _leftParen;
- static const String startFunctionArgumentsString = _leftParenString;
- static const int endFunctionArguments = _rightParen;
- static const String endFunctionArgumentsString = _rightParenString;
- static const int startOptionalGroup = _leftBracket;
- static const String startOptionalGroupString = _leftBracketString;
- static const int endOptionalGroup = _rightBracket;
- static const String endOptionalGroupString = _rightBracketString;
- static const int startNamedGroup = _leftBrace;
- static const String startNamedGroupString = _leftBraceString;
- static const int endNamedGroup = _rightBrace;
- static const String endNamedGroupString = _rightBraceString;
- static const int nameSeparator = _colon;
- static const String nameSeparatorString = _colonString;
- static const int requiredNameSeparator = _exclamation;
- static const String requiredNameSeparatorString = _exclamationString;
-
- static const int genericFunctionTypeParameterIndex = _circumflex;
- static const String genericFunctionTypeParameterIndexString =
- _circumflexString;
-
- static const int extensionOp = _ampersand;
- static const String extensionOpString = _ampersandString;
- static const int pushNeverExtension = 0;
- static const String pushNeverExtensionString = '$pushNeverExtension';
- static const int pushAnyExtension = 1;
- static const String pushAnyExtensionString = '$pushAnyExtension';
-
- // Number and name components.
-
- static bool isDigit(int code) => code >= _digit0 && code <= _digit9;
- static int digitValue(int code) => code - _digit0;
-
- static bool isIdentifierStart(int ch) =>
- (((ch | 32) - _lowercaseA) & 0xffff) < 26 ||
- (ch == _underscore) ||
- (ch == _dollar);
-
- static const int period = _period;
-
- // Private names.
-
- static const int _formfeed = 0x0C;
- static const String _formfeedString = '\f';
-
- static const int _space = 0x20;
- static const String _spaceString = ' ';
- static const int _exclamation = 0x21;
- static const String _exclamationString = '!';
- static const int _hash = 0x23;
- static const String _hashString = '#';
- static const int _dollar = 0x24;
- static const String _dollarString = r'$';
- static const int _percent = 0x25;
- static const String _percentString = '%';
- static const int _ampersand = 0x26;
- static const String _ampersandString = '&';
- static const int _apostrophe = 0x27;
- static const String _apostropheString = "'";
- static const int _leftParen = 0x28;
- static const String _leftParenString = '(';
- static const int _rightParen = 0x29;
- static const String _rightParenString = ')';
- static const int _asterisk = 0x2A;
- static const String _asteriskString = '*';
- static const int _plus = 0x2B;
- static const String _plusString = '+';
- static const int _comma = 0x2C;
- static const String _commaString = ',';
- static const int _minus = 0x2D;
- static const String _minusString = '-';
- static const int _period = 0x2E;
- static const String _periodString = '.';
- static const int _slash = 0x2F;
- static const String _slashString = '/';
-
- static const int _digit0 = 0x30;
- static const int _digit9 = 0x39;
-
- static const int _colon = 0x3A;
- static const String _colonString = ':';
- static const int _semicolon = 0x3B;
- static const String _semicolonString = ';';
- static const int _lessThan = 0x3C;
- static const String _lessThanString = '<';
- static const int _equals = 0x3D;
- static const String _equalsString = '=';
- static const int _greaterThan = 0x3E;
- static const String _greaterThanString = '>';
- static const int _question = 0x3F;
- static const String _questionString = '?';
- static const int _at = 0x40;
- static const String _atString = '@';
-
- static const int _uppercaseA = 0x41;
- static const int _uppercaseZ = 0x5A;
-
- static const int _leftBracket = 0x5B;
- static const String _leftBracketString = '[';
- static const int _backslash = 0x5C;
- static const String _backslashString = r'\';
- static const int _rightBracket = 0x5D;
- static const String _rightBracketString = ']';
- static const int _circumflex = 0x5E;
- static const String _circumflexString = '^';
- static const int _underscore = 0x5F;
- static const String _underscoreString = '_';
- static const int _backtick = 0x60;
- static const String _backtickString = '`';
-
- static const int _lowercaseA = 0x61;
- static const int _lowercaseZ = 0x7A;
-
- static const int _leftBrace = 0x7B;
- static const String _leftBraceString = '{';
- static const int _vertical = 0x7C;
- static const String _verticalString = '|';
- static const int _rightBrace = 0x7D;
- static const String _rightBraceString = '}';
- static const int _tilde = 0x7E;
- static const String _tildeString = '~';
-
- static void testEquivalence() {
- void test(String label, int charCode, String str) {
- if (String.fromCharCode(charCode) != str) {
- throw StateError("$label: String.fromCharCode($charCode) != $str");
- }
- }
-
- void testExtension(String label, int op, String str) {
- if ('$op' != str) {
- throw StateError("$label: $op.toString() != $str");
- }
- }
-
- test("separator", separator, separatorString);
- test("toType", toType, toTypeString);
- test("pushErased", pushErased, pushErasedString);
- test("pushDynamic", pushDynamic, pushDynamicString);
- test("pushVoid", pushVoid, pushVoidString);
- test("wrapStar", wrapStar, wrapStarString);
- test("wrapQuestion", wrapQuestion, wrapQuestionString);
- test("wrapFutureOr", wrapFutureOr, wrapFutureOrString);
- test("startTypeArguments", startTypeArguments, startTypeArgumentsString);
- test("endTypeArguments", endTypeArguments, endTypeArgumentsString);
- test("startFunctionArguments", startFunctionArguments,
- startFunctionArgumentsString);
- test("endFunctionArguments", endFunctionArguments,
- endFunctionArgumentsString);
- test("startOptionalGroup", startOptionalGroup, startOptionalGroupString);
- test("endOptionalGroup", endOptionalGroup, endOptionalGroupString);
- test("startNamedGroup", startNamedGroup, startNamedGroupString);
- test("endNamedGroup", endNamedGroup, endNamedGroupString);
- test("nameSeparator", nameSeparator, nameSeparatorString);
- test("requiredNameSeparator", requiredNameSeparator,
- requiredNameSeparatorString);
- test("genericFunctionTypeParameterIndex", genericFunctionTypeParameterIndex,
- genericFunctionTypeParameterIndexString);
- test("extensionOp", extensionOp, extensionOpString);
- testExtension(
- "pushNeverExtension", pushNeverExtension, pushNeverExtensionString);
- testExtension("pushAnyExtension", pushAnyExtension, pushAnyExtensionString);
-
- test("_formfeed", _formfeed, _formfeedString);
- test("_space", _space, _spaceString);
- test("_exclamation", _exclamation, _exclamationString);
- test("_hash", _hash, _hashString);
- test("_dollar", _dollar, _dollarString);
- test("_percent", _percent, _percentString);
- test("_ampersand", _ampersand, _ampersandString);
- test("_apostrophe", _apostrophe, _apostropheString);
- test("_leftParen", _leftParen, _leftParenString);
- test("_rightParen", _rightParen, _rightParenString);
- test("_asterisk", _asterisk, _asteriskString);
- test("_plus", _plus, _plusString);
- test("_comma", _comma, _commaString);
- test("_minus", _minus, _minusString);
- test("_period", _period, _periodString);
- test("_slash", _slash, _slashString);
- test("_colon", _colon, _colonString);
- test("_semicolon", _semicolon, _semicolonString);
- test("_lessThan", _lessThan, _lessThanString);
- test("_equals", _equals, _equalsString);
- test("_greaterThan", _greaterThan, _greaterThanString);
- test("_question", _question, _questionString);
- test("_at", _at, _atString);
- test("_leftBracket", _leftBracket, _leftBracketString);
- test("_backslash", _backslash, _backslashString);
- test("_rightBracket", _rightBracket, _rightBracketString);
- test("_circumflex", _circumflex, _circumflexString);
- test("_underscore", _underscore, _underscoreString);
- test("_backtick", _backtick, _backtickString);
- test("_leftBrace", _leftBrace, _leftBraceString);
- test("_vertical", _vertical, _verticalString);
- test("_rightBrace", _rightBrace, _rightBraceString);
- test("_tilde", _tilde, _tildeString);
- }
-}
diff --git a/sdk/lib/_internal/js_runtime/lib/shared/async_await_error_codes.dart b/sdk/lib/_internal/js_runtime/lib/synced/async_await_error_codes.dart
similarity index 100%
rename from sdk/lib/_internal/js_runtime/lib/shared/async_await_error_codes.dart
rename to sdk/lib/_internal/js_runtime/lib/synced/async_await_error_codes.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/shared/embedded_names.dart b/sdk/lib/_internal/js_runtime/lib/synced/embedded_names.dart
similarity index 100%
rename from sdk/lib/_internal/js_runtime/lib/shared/embedded_names.dart
rename to sdk/lib/_internal/js_runtime/lib/synced/embedded_names.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/rti.dart b/sdk/lib/_internal/js_shared/lib/rti.dart
similarity index 100%
rename from sdk/lib/_internal/js_runtime/lib/rti.dart
rename to sdk/lib/_internal/js_shared/lib/rti.dart
diff --git a/pkg/js_runtime/lib/shared/recipe_syntax.dart b/sdk/lib/_internal/js_shared/lib/synced/recipe_syntax.dart
similarity index 98%
copy from pkg/js_runtime/lib/shared/recipe_syntax.dart
copy to sdk/lib/_internal/js_shared/lib/synced/recipe_syntax.dart
index 7305491..3ccec60 100644
--- a/pkg/js_runtime/lib/shared/recipe_syntax.dart
+++ b/sdk/lib/_internal/js_shared/lib/synced/recipe_syntax.dart
@@ -6,8 +6,8 @@
/// Constants and predicates used for encoding and decoding type recipes.
///
-/// This library is shared between the compiler and the runtime system.
-library dart2js._recipe_syntax;
+/// This library is synchronized between the compiler and the runtime system.
+library js_shared._recipe_syntax;
abstract class Recipe {
Recipe._();
diff --git a/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart b/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart
index 49845a2..5a357e5 100644
--- a/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart
+++ b/sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart
@@ -147,7 +147,7 @@
categories: "", documented: false, platforms: DART2JS_PLATFORM),
"_late_helper": const LibraryInfo("_internal/js_runtime/lib/late_helper.dart",
categories: "", documented: false, platforms: DART2JS_PLATFORM),
- "_rti": const LibraryInfo("_internal/js_runtime/lib/rti.dart",
+ "_rti": const LibraryInfo("_internal/js_shared/lib/rti.dart",
categories: "", documented: false, platforms: DART2JS_PLATFORM),
"_dart2js_runtime_metrics": const LibraryInfo(
"_internal/js_runtime/lib/dart2js_runtime_metrics.dart",
@@ -172,17 +172,17 @@
documented: false,
platforms: DART2JS_PLATFORM),
"_js_embedded_names": const LibraryInfo(
- "_internal/js_runtime/lib/shared/embedded_names.dart",
+ "_internal/js_runtime/lib/synced/embedded_names.dart",
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
"_async_await_error_codes": const LibraryInfo(
- "_internal/js_runtime/lib/shared/async_await_error_codes.dart",
+ "_internal/js_runtime/lib/synced/async_await_error_codes.dart",
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
"_recipe_syntax": const LibraryInfo(
- "_internal/js_runtime/lib/shared/recipe_syntax.dart",
+ "_internal/js_shared/lib/synced/recipe_syntax.dart",
categories: "",
documented: false,
platforms: DART2JS_PLATFORM),
diff --git a/sdk/lib/libraries.json b/sdk/lib/libraries.json
index b72ab82..6f33d88 100644
--- a/sdk/lib/libraries.json
+++ b/sdk/lib/libraries.json
@@ -369,7 +369,7 @@
"uri": "_internal/js_runtime/lib/late_helper.dart"
},
"_rti": {
- "uri": "_internal/js_runtime/lib/rti.dart"
+ "uri": "_internal/js_shared/lib/rti.dart"
},
"_interceptors": {
"uri": "_internal/js_runtime/lib/interceptors.dart"
@@ -384,13 +384,13 @@
"uri": "_internal/js_runtime/lib/js_primitives.dart"
},
"_js_embedded_names": {
- "uri": "_internal/js_runtime/lib/shared/embedded_names.dart"
+ "uri": "_internal/js_runtime/lib/synced/embedded_names.dart"
},
"_async_await_error_codes": {
- "uri": "_internal/js_runtime/lib/shared/async_await_error_codes.dart"
+ "uri": "_internal/js_runtime/lib/synced/async_await_error_codes.dart"
},
"_recipe_syntax": {
- "uri": "_internal/js_runtime/lib/shared/recipe_syntax.dart"
+ "uri": "_internal/js_shared/lib/synced/recipe_syntax.dart"
}
}
},
diff --git a/sdk/lib/libraries.yaml b/sdk/lib/libraries.yaml
index 92231cb..ed11fa5 100644
--- a/sdk/lib/libraries.yaml
+++ b/sdk/lib/libraries.yaml
@@ -337,7 +337,7 @@
uri: "_internal/js_runtime/lib/late_helper.dart"
_rti:
- uri: "_internal/js_runtime/lib/rti.dart"
+ uri: "_internal/js_shared/lib/rti.dart"
_interceptors:
uri: "_internal/js_runtime/lib/interceptors.dart"
@@ -352,13 +352,13 @@
uri: "_internal/js_runtime/lib/js_primitives.dart"
_js_embedded_names:
- uri: "_internal/js_runtime/lib/shared/embedded_names.dart"
+ uri: "_internal/js_runtime/lib/synced/embedded_names.dart"
_async_await_error_codes:
- uri: "_internal/js_runtime/lib/shared/async_await_error_codes.dart"
+ uri: "_internal/js_runtime/lib/synced/async_await_error_codes.dart"
_recipe_syntax:
- uri: "_internal/js_runtime/lib/shared/recipe_syntax.dart"
+ uri: "_internal/js_shared/lib/synced/recipe_syntax.dart"
dartdevc:
libraries:
diff --git a/tools/VERSION b/tools/VERSION
index c7f1750..557f70e 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -27,5 +27,5 @@
MAJOR 2
MINOR 18
PATCH 0
-PRERELEASE 130
+PRERELEASE 131
PRERELEASE_PATCH 0
\ No newline at end of file
diff --git a/tools/bots/test_matrix.json b/tools/bots/test_matrix.json
index 53e919c..c2fc5a0 100644
--- a/tools/bots/test_matrix.json
+++ b/tools/bots/test_matrix.json
@@ -183,6 +183,11 @@
"dart2wasm_hostasserts": [
".dart_tool/package_config.json",
"out/ReleaseX64/dart",
+ "out/ReleaseX64/dart_precompiled_runtime",
+ "out/ReleaseX64/dart2wasm.snapshot",
+ "out/ReleaseX64/dart2wasm_asserts.snapshot",
+ "out/ReleaseX64/dart2wasm_outline.dill",
+ "out/ReleaseX64/dart2wasm_platform.dill",
"pkg/",
"runtime/tests/",
"samples-dev/",
@@ -1473,8 +1478,10 @@
"vm-kernel-precomp-linux-release-simarm64",
"vm-kernel-precomp-linux-release-simriscv32",
"vm-kernel-precomp-linux-release-simriscv64",
+ "vm-kernel-precomp-mac-product-x64",
"vm-kernel-precomp-mac-release-simarm64",
"vm-kernel-precomp-mac-release-simarm64c",
+ "vm-kernel-precomp-win-product-x64",
"vm-kernel-precomp-win-release-x64",
"vm-kernel-precomp-win-release-x64c"
],
@@ -3029,7 +3036,7 @@
"corelib",
"web/wasm"
],
- "shards": 30,
+ "shards": 3,
"fileset": "dart2wasm_hostasserts"
}
]