Skip to content

Commit 2585dee

Browse files
DanTupCommit Queue
authored andcommitted
[analysis_server] Remove non-null assertion in TypeHierarchy
Fixes #61420 Change-Id: I1d9863a1e42c7d80ab742d3cc9648b281fba56a6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452060 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Keerti Parthasarathy <[email protected]> Commit-Queue: Keerti Parthasarathy <[email protected]>
1 parent 64d963b commit 2585dee

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

pkg/analysis_server/lib/src/search/type_hierarchy.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class TypeHierarchyComputer {
159159

160160
class TypeHierarchyComputerHelper {
161161
final Element pivotElement;
162-
final LibraryElement pivotLibrary;
162+
final LibraryElement? pivotLibrary;
163163
final ElementKind pivotKind;
164164
final String? pivotName;
165165
final bool pivotFieldFinal;
@@ -192,7 +192,7 @@ class TypeHierarchyComputerHelper {
192192

193193
return TypeHierarchyComputerHelper(
194194
pivotElement,
195-
pivotElement.library!,
195+
pivotElement.library,
196196
pivotElement.kind,
197197
pivotElement.name,
198198
pivotFieldFinal,
@@ -211,6 +211,12 @@ class TypeHierarchyComputerHelper {
211211
if (pivotName == null) {
212212
return null;
213213
}
214+
215+
var pivotLibrary = this.pivotLibrary;
216+
if (pivotLibrary == null) {
217+
return null;
218+
}
219+
214220
ExecutableElement? result;
215221
// try to find in the class itself
216222
if (pivotKind == ElementKind.METHOD) {

pkg/analysis_server/test/lsp/implementation_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ abstract class MyInterface {
237237
await _testMarkedContent(content, otherContent: mixinsContent);
238238
}
239239

240+
Future<void> test_never_issue61420() => _testMarkedContent('''
241+
Ne^ver value = throw '';
242+
''', expectResults: false);
243+
240244
Future<void> test_nonDartFile() async {
241245
newFile(pubspecFilePath, simplePubspecContent);
242246
await initialize();

pkg/analysis_server/test/search/type_hierarchy_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,6 +1657,14 @@ extension type E(A it) implements A {
16571657
expect(itemE.memberElement, isNull);
16581658
}
16591659

1660+
Future<void> test_never_issue61420() async {
1661+
addTestFile('''
1662+
Never value = throw 'error';
1663+
''');
1664+
var items = await _getTypeHierarchyOrNull('Never');
1665+
expect(items, isNull);
1666+
}
1667+
16601668
void _assertMember(TypeHierarchyItem item, String search) {
16611669
expect(item.memberElement!.location!.offset, findOffset(search));
16621670
}
@@ -1683,6 +1691,7 @@ extension type E(A it) implements A {
16831691
await waitForTasksFinished();
16841692
var request = _createGetTypeHierarchyRequest(search, superOnly: superOnly);
16851693
var response = await serverChannel.simulateRequestFromClient(request);
1694+
expect(response.error, isNull);
16861695
return SearchGetTypeHierarchyResult.fromResponse(
16871696
response,
16881697
clientUriConverter: server.uriConverter,

0 commit comments

Comments
 (0)