Merge pull request #22145 from rintaro/5.0-sourcekit-rdar47426948

[5.0][SourceKit] Fix a crash in SwiftDocumentStructureWalker::getObjCSelectorName()
diff --git a/test/SourceKit/DocumentStructure/rdar47426948.swift b/test/SourceKit/DocumentStructure/rdar47426948.swift
new file mode 100644
index 0000000..fbcd96d
--- /dev/null
+++ b/test/SourceKit/DocumentStructure/rdar47426948.swift
@@ -0,0 +1,40 @@
+// RUN: %sourcekitd-test -req=structure %s -- %s | %FileCheck %s
+
+class C {
+  @IBAction init(foo: Void) {}
+  @IBAction init(bar: ()) {}
+  @IBAction init(baz: Int) {}
+  @IBAction func methodName(foo: ()) {}
+  @IBAction func methodName(bar: Void) {}
+  @IBAction func methodName(baz: Int) {}
+  @IBAction deinit {}
+}
+
+// CHECK: {
+// CHECK:   key.name: "init(foo:)",
+// CHECK-NOT:   key.selector_name
+// CHECK: }
+// CHECK: {
+// CHECK:   key.name: "init(bar:)",
+// CHECK-NOT:   key.selector_name
+// CHECK: }
+// CHECK: {
+// CHECK:   key.name: "init(baz:)",
+// CHECK-NOT:   key.selector_name
+// CHECK: }
+// CHECK: {
+// CHECK:   key.name: "methodName(foo:)",
+// CHECK:   key.selector_name: "methodNameWithFoo:"
+// CHECK: }
+// CHECK: {
+// CHECK:   key.name: "methodName(bar:)",
+// CHECK:   key.selector_name: "methodNameWithBar:"
+// CHECK: }
+// CHECK: {
+// CHECK:   key.name: "methodName(baz:)",
+// CHECK:   key.selector_name: "methodNameWithBaz:"
+// CHECK: }
+// CHECK: {
+// CHECK:   key.name: "deinit",
+// CHECK-NOT:   key.selector_name
+// CHECK: }
diff --git a/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp b/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
index 2d84e86..6f88937 100644
--- a/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
+++ b/tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
@@ -1266,8 +1266,8 @@
   }
 
   StringRef getObjCSelectorName(const Decl *D, SmallString<64> &Buf) {
-    if (auto FuncD = dyn_cast_or_null<AbstractFunctionDecl>(D)) {
-      // We only vend the selector name for @IBAction methods.
+    // We only vend the selector name for @IBAction methods.
+    if (auto FuncD = dyn_cast_or_null<FuncDecl>(D)) {
       if (FuncD->getAttrs().hasAttribute<IBActionAttr>())
         return FuncD->getObjCSelector().getString(Buf);
     }