Issue 33518. Fix for subtypes() in parts without library.
R=brianwilkerson@google.com, paulberry@google.com
Bug: https://github.com/dart-lang/sdk/issues/33518
Change-Id: I368495db5dfa3d4fd64224af9860699fa313f026
Reviewed-on: https://dart-review.googlesource.com/62240
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/analysis/search.dart b/pkg/analyzer/lib/src/dart/analysis/search.dart
index e017334..b5417e9 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -387,7 +387,7 @@
if (index != null) {
for (AnalysisDriverSubtype subtype in index.subtypes) {
if (subtype.supertypes.contains(id)) {
- FileState library = file.isPart ? file.library : file;
+ FileState library = file.library ?? file;
results.add(new SubtypeResult(
library.uriStr,
library.uriStr + ';' + file.uriStr + ';' + subtype.name,
diff --git a/pkg/analyzer/test/src/dart/analysis/search_test.dart b/pkg/analyzer/test/src/dart/analysis/search_test.dart
index d667f0e..d3573f1 100644
--- a/pkg/analyzer/test/src/dart/analysis/search_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/search_test.dart
@@ -1646,6 +1646,23 @@
}
}
+ test_subtypes_partWithoutLibrary() async {
+ await _resolveTestUnit('''
+part of lib;
+
+class A {}
+class B extends A {}
+''');
+ ClassElement a = _findElement('A');
+
+ List<SubtypeResult> subtypes = await driver.search.subtypes(type: a);
+ expect(subtypes, hasLength(1));
+
+ SubtypeResult b = subtypes.singleWhere((r) => r.name == 'B');
+ expect(b.libraryUri, testUri);
+ expect(b.id, '$testUri;$testUri;B');
+ }
+
test_subtypes_discover() async {
var pathT = _p('/test/lib/t.dart');
var pathA = _p('/aaa/lib/a.dart');