Skip to content

Commit 3e85e96

Browse files
committed
[SourceKit] Fix a crash in SwiftDocumentStructureWalker::getObjCSelectorName()
SourceKit document structure request used to crash if if there's inititalizer with single named parameter with `@IBAction` attribute. This used to happen because ConstructorDecl::isObjCZeroParameterWithLongSelector() requires interface type of the parameter but the constructor doesn't have it at this stage. This change fixes that by not vending ObjC name for constructor or destructors. rdar://problem/47426948 (cherry picked from commit 606b551)
1 parent a8a9978 commit 3e85e96

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// RUN: %sourcekitd-test -req=structure %s -- %s | %FileCheck %s
2+
3+
class C {
4+
@IBAction init(foo: Void) {}
5+
@IBAction init(bar: ()) {}
6+
@IBAction init(baz: Int) {}
7+
@IBAction func methodName(foo: ()) {}
8+
@IBAction func methodName(bar: Void) {}
9+
@IBAction func methodName(baz: Int) {}
10+
@IBAction deinit {}
11+
}
12+
13+
// CHECK: {
14+
// CHECK: key.name: "init(foo:)",
15+
// CHECK-NOT: key.selector_name
16+
// CHECK: }
17+
// CHECK: {
18+
// CHECK: key.name: "init(bar:)",
19+
// CHECK-NOT: key.selector_name
20+
// CHECK: }
21+
// CHECK: {
22+
// CHECK: key.name: "init(baz:)",
23+
// CHECK-NOT: key.selector_name
24+
// CHECK: }
25+
// CHECK: {
26+
// CHECK: key.name: "methodName(foo:)",
27+
// CHECK: key.selector_name: "methodNameWithFoo:"
28+
// CHECK: }
29+
// CHECK: {
30+
// CHECK: key.name: "methodName(bar:)",
31+
// CHECK: key.selector_name: "methodNameWithBar:"
32+
// CHECK: }
33+
// CHECK: {
34+
// CHECK: key.name: "methodName(baz:)",
35+
// CHECK: key.selector_name: "methodNameWithBaz:"
36+
// CHECK: }
37+
// CHECK: {
38+
// CHECK: key.name: "deinit",
39+
// CHECK-NOT: key.selector_name
40+
// CHECK: }

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,8 @@ class SwiftDocumentStructureWalker: public ide::SyntaxModelWalker {
12661266
}
12671267

12681268
StringRef getObjCSelectorName(const Decl *D, SmallString<64> &Buf) {
1269-
if (auto FuncD = dyn_cast_or_null<AbstractFunctionDecl>(D)) {
1270-
// We only vend the selector name for @IBAction methods.
1269+
// We only vend the selector name for @IBAction methods.
1270+
if (auto FuncD = dyn_cast_or_null<FuncDecl>(D)) {
12711271
if (FuncD->getAttrs().hasAttribute<IBActionAttr>())
12721272
return FuncD->getObjCSelector().getString(Buf);
12731273
}

0 commit comments

Comments
 (0)