Skip to content

[5.3][SourceKit] Fix unreachable hit in DocumentStructureWalker #31341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test/SourceKit/DocumentStructure/Inputs/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,9 @@ var var_with_didset = 10 {
var thing: NSObject {get}
}
#endif

class A {
#if true
@IBAction @objc func foo(a: Int) {}
#endif
}
50 changes: 49 additions & 1 deletion test/SourceKit/DocumentStructure/structure.swift.empty.response
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
key.offset: 0,
key.length: 2787,
key.length: 2858,
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
key.substructure: [
{
Expand Down Expand Up @@ -1689,6 +1689,54 @@
key.bodylength: 3
}
]
},
{
key.kind: source.lang.swift.decl.class,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "A",
key.offset: 2788,
key.length: 69,
key.nameoffset: 2794,
key.namelength: 1,
key.bodyoffset: 2797,
key.bodylength: 59,
key.substructure: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "foo(a:)",
key.offset: 2827,
key.length: 19,
key.selector_name: "fooWithA:",
key.nameoffset: 2832,
key.namelength: 11,
key.bodyoffset: 2845,
key.bodylength: 0,
key.attributes: [
{
key.offset: 2821,
key.length: 5,
key.attribute: source.decl.attribute.objc.name
},
{
key.offset: 2811,
key.length: 9,
key.attribute: source.decl.attribute.ibaction
}
],
key.substructure: [
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "a",
key.offset: 2836,
key.length: 6,
key.typename: "Int",
key.nameoffset: 2836,
key.namelength: 1
}
]
}
]
}
],
key.diagnostics: [
Expand Down
50 changes: 49 additions & 1 deletion test/SourceKit/DocumentStructure/structure.swift.foobar.response
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
key.offset: 0,
key.length: 2787,
key.length: 2858,
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
key.substructure: [
{
Expand Down Expand Up @@ -1689,6 +1689,54 @@
key.bodylength: 3
}
]
},
{
key.kind: source.lang.swift.decl.class,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "A",
key.offset: 2788,
key.length: 69,
key.nameoffset: 2794,
key.namelength: 1,
key.bodyoffset: 2797,
key.bodylength: 59,
key.substructure: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "foo(a:)",
key.offset: 2827,
key.length: 19,
key.selector_name: "fooWithA:",
key.nameoffset: 2832,
key.namelength: 11,
key.bodyoffset: 2845,
key.bodylength: 0,
key.attributes: [
{
key.offset: 2821,
key.length: 5,
key.attribute: source.decl.attribute.objc.name
},
{
key.offset: 2811,
key.length: 9,
key.attribute: source.decl.attribute.ibaction
}
],
key.substructure: [
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "a",
key.offset: 2836,
key.length: 6,
key.typename: "Int",
key.nameoffset: 2836,
key.namelength: 1
}
]
}
]
}
],
key.diagnostics: [
Expand Down
50 changes: 49 additions & 1 deletion test/SourceKit/DocumentStructure/structure.swift.response
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
key.offset: 0,
key.length: 2787,
key.length: 2858,
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
key.substructure: [
{
Expand Down Expand Up @@ -1689,6 +1689,54 @@
key.bodylength: 3
}
]
},
{
key.kind: source.lang.swift.decl.class,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "A",
key.offset: 2788,
key.length: 69,
key.nameoffset: 2794,
key.namelength: 1,
key.bodyoffset: 2797,
key.bodylength: 59,
key.substructure: [
{
key.kind: source.lang.swift.decl.function.method.instance,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "foo(a:)",
key.offset: 2827,
key.length: 19,
key.selector_name: "fooWithA:",
key.nameoffset: 2832,
key.namelength: 11,
key.bodyoffset: 2845,
key.bodylength: 0,
key.attributes: [
{
key.offset: 2821,
key.length: 5,
key.attribute: source.decl.attribute.objc.name
},
{
key.offset: 2811,
key.length: 9,
key.attribute: source.decl.attribute.ibaction
}
],
key.substructure: [
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "a",
key.offset: 2836,
key.length: 6,
key.typename: "Int",
key.nameoffset: 2836,
key.namelength: 1
}
]
}
]
}
],
key.diagnostics: [
Expand Down
6 changes: 4 additions & 2 deletions tools/SourceKit/lib/SwiftLang/SwiftEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1363,8 +1363,10 @@ class SwiftDocumentStructureWalker: public ide::SyntaxModelWalker {
// We only vend the selector name for @IBAction and @IBSegueAction methods.
if (auto FuncD = dyn_cast_or_null<FuncDecl>(D)) {
if (FuncD->getAttrs().hasAttribute<IBActionAttr>() ||
FuncD->getAttrs().hasAttribute<IBSegueActionAttr>())
return FuncD->getObjCSelector().getString(Buf);
FuncD->getAttrs().hasAttribute<IBSegueActionAttr>()) {
return FuncD->getObjCSelector(DeclName(), /*skipIsObjCResolution*/true)
.getString(Buf);
}
}
return StringRef();
}
Expand Down