Skip to content

Commit 815310a

Browse files
authored
Merge pull request #19378 from slavapestov/index-while-building-crash
Index: Don't crash if an optional requirement is missing its witness
2 parents e1901fd + 28c5ad3 commit 815310a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/Index/Index.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,9 @@ bool IndexSwiftASTWalker::handleValueWitnesses(Decl *D, SmallVectorImpl<ValueWit
661661
return;
662662

663663
auto *decl = witness.getDecl();
664+
if (decl == nullptr)
665+
return;
666+
664667
if (decl->getDeclContext() == DC) {
665668
explicitValueWitnesses.push_back(ValueWitness{decl, req});
666669
} else {

test/Index/objc_conformances.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %target-swift-ide-test(mock-sdk: %clang-importer-sdk) -print-indexed-symbols -source-filename %s | %FileCheck %s
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
// Make sure we properly handle missing optional requirements.
7+
@objc protocol P {
8+
@objc optional func f()
9+
func g()
10+
}
11+
12+
class C : P {
13+
@objc func g() {}
14+
// CHECK: [[@LINE-1]]:14 | instance-method/Swift | g() | s:14swift_ide_test1CC1gyyF | Def,Dyn,RelChild,RelOver | rel: 2
15+
// CHECK: RelOver | instance-method/Swift | g() | c:@M@swift_ide_test@objc(pl)P(im)g
16+
// CHECK: RelChild | class/Swift | C | s:14swift_ide_test1CC
17+
}

0 commit comments

Comments
 (0)