Skip to content

Commit 43eceef

Browse files
author
Nathan Hawes
committed
[SourceKit] Fix unreachable hit in DocumentStructureWalker
Resolves rdar://problem/61967092
1 parent 82d73b5 commit 43eceef

File tree

5 files changed

+157
-5
lines changed

5 files changed

+157
-5
lines changed

test/SourceKit/DocumentStructure/Inputs/main.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,9 @@ var var_with_didset = 10 {
178178
var thing: NSObject {get}
179179
}
180180
#endif
181+
182+
class A {
183+
#if true
184+
@IBAction @objc func foo(a: Int) {}
185+
#endif
186+
}

test/SourceKit/DocumentStructure/structure.swift.empty.response

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2787,
3+
key.length: 2858,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1689,6 +1689,54 @@
16891689
key.bodylength: 3
16901690
}
16911691
]
1692+
},
1693+
{
1694+
key.kind: source.lang.swift.decl.class,
1695+
key.accessibility: source.lang.swift.accessibility.internal,
1696+
key.name: "A",
1697+
key.offset: 2788,
1698+
key.length: 69,
1699+
key.nameoffset: 2794,
1700+
key.namelength: 1,
1701+
key.bodyoffset: 2797,
1702+
key.bodylength: 59,
1703+
key.substructure: [
1704+
{
1705+
key.kind: source.lang.swift.decl.function.method.instance,
1706+
key.accessibility: source.lang.swift.accessibility.internal,
1707+
key.name: "foo(a:)",
1708+
key.offset: 2827,
1709+
key.length: 19,
1710+
key.selector_name: "fooWithA:",
1711+
key.nameoffset: 2832,
1712+
key.namelength: 11,
1713+
key.bodyoffset: 2845,
1714+
key.bodylength: 0,
1715+
key.attributes: [
1716+
{
1717+
key.offset: 2821,
1718+
key.length: 5,
1719+
key.attribute: source.decl.attribute.objc.name
1720+
},
1721+
{
1722+
key.offset: 2811,
1723+
key.length: 9,
1724+
key.attribute: source.decl.attribute.ibaction
1725+
}
1726+
],
1727+
key.substructure: [
1728+
{
1729+
key.kind: source.lang.swift.decl.var.parameter,
1730+
key.name: "a",
1731+
key.offset: 2836,
1732+
key.length: 6,
1733+
key.typename: "Int",
1734+
key.nameoffset: 2836,
1735+
key.namelength: 1
1736+
}
1737+
]
1738+
}
1739+
]
16921740
}
16931741
],
16941742
key.diagnostics: [

test/SourceKit/DocumentStructure/structure.swift.foobar.response

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2787,
3+
key.length: 2858,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1689,6 +1689,54 @@
16891689
key.bodylength: 3
16901690
}
16911691
]
1692+
},
1693+
{
1694+
key.kind: source.lang.swift.decl.class,
1695+
key.accessibility: source.lang.swift.accessibility.internal,
1696+
key.name: "A",
1697+
key.offset: 2788,
1698+
key.length: 69,
1699+
key.nameoffset: 2794,
1700+
key.namelength: 1,
1701+
key.bodyoffset: 2797,
1702+
key.bodylength: 59,
1703+
key.substructure: [
1704+
{
1705+
key.kind: source.lang.swift.decl.function.method.instance,
1706+
key.accessibility: source.lang.swift.accessibility.internal,
1707+
key.name: "foo(a:)",
1708+
key.offset: 2827,
1709+
key.length: 19,
1710+
key.selector_name: "fooWithA:",
1711+
key.nameoffset: 2832,
1712+
key.namelength: 11,
1713+
key.bodyoffset: 2845,
1714+
key.bodylength: 0,
1715+
key.attributes: [
1716+
{
1717+
key.offset: 2821,
1718+
key.length: 5,
1719+
key.attribute: source.decl.attribute.objc.name
1720+
},
1721+
{
1722+
key.offset: 2811,
1723+
key.length: 9,
1724+
key.attribute: source.decl.attribute.ibaction
1725+
}
1726+
],
1727+
key.substructure: [
1728+
{
1729+
key.kind: source.lang.swift.decl.var.parameter,
1730+
key.name: "a",
1731+
key.offset: 2836,
1732+
key.length: 6,
1733+
key.typename: "Int",
1734+
key.nameoffset: 2836,
1735+
key.namelength: 1
1736+
}
1737+
]
1738+
}
1739+
]
16921740
}
16931741
],
16941742
key.diagnostics: [

test/SourceKit/DocumentStructure/structure.swift.response

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2787,
3+
key.length: 2858,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1689,6 +1689,54 @@
16891689
key.bodylength: 3
16901690
}
16911691
]
1692+
},
1693+
{
1694+
key.kind: source.lang.swift.decl.class,
1695+
key.accessibility: source.lang.swift.accessibility.internal,
1696+
key.name: "A",
1697+
key.offset: 2788,
1698+
key.length: 69,
1699+
key.nameoffset: 2794,
1700+
key.namelength: 1,
1701+
key.bodyoffset: 2797,
1702+
key.bodylength: 59,
1703+
key.substructure: [
1704+
{
1705+
key.kind: source.lang.swift.decl.function.method.instance,
1706+
key.accessibility: source.lang.swift.accessibility.internal,
1707+
key.name: "foo(a:)",
1708+
key.offset: 2827,
1709+
key.length: 19,
1710+
key.selector_name: "fooWithA:",
1711+
key.nameoffset: 2832,
1712+
key.namelength: 11,
1713+
key.bodyoffset: 2845,
1714+
key.bodylength: 0,
1715+
key.attributes: [
1716+
{
1717+
key.offset: 2821,
1718+
key.length: 5,
1719+
key.attribute: source.decl.attribute.objc.name
1720+
},
1721+
{
1722+
key.offset: 2811,
1723+
key.length: 9,
1724+
key.attribute: source.decl.attribute.ibaction
1725+
}
1726+
],
1727+
key.substructure: [
1728+
{
1729+
key.kind: source.lang.swift.decl.var.parameter,
1730+
key.name: "a",
1731+
key.offset: 2836,
1732+
key.length: 6,
1733+
key.typename: "Int",
1734+
key.nameoffset: 2836,
1735+
key.namelength: 1
1736+
}
1737+
]
1738+
}
1739+
]
16921740
}
16931741
],
16941742
key.diagnostics: [

tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,8 +1363,10 @@ class SwiftDocumentStructureWalker: public ide::SyntaxModelWalker {
13631363
// We only vend the selector name for @IBAction and @IBSegueAction methods.
13641364
if (auto FuncD = dyn_cast_or_null<FuncDecl>(D)) {
13651365
if (FuncD->getAttrs().hasAttribute<IBActionAttr>() ||
1366-
FuncD->getAttrs().hasAttribute<IBSegueActionAttr>())
1367-
return FuncD->getObjCSelector().getString(Buf);
1366+
FuncD->getAttrs().hasAttribute<IBSegueActionAttr>()) {
1367+
return FuncD->getObjCSelector(DeclName(), /*skipIsObjCResolution*/true)
1368+
.getString(Buf);
1369+
}
13681370
}
13691371
return StringRef();
13701372
}

0 commit comments

Comments
 (0)