Skip to content

[SR-9576][SourceKit] Fix syntax type when rethrows is present #22017

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 1 commit into from
Jan 24, 2019
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
2 changes: 2 additions & 0 deletions lib/IDE/SyntaxModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,6 +1041,8 @@ bool ModelASTWalker::handleSpecialDeclAttribute(const DeclAttribute *D,
TokenNodes = TokenNodes.slice(I);
return true;
}
if (isa<RethrowsAttr>(D))
return true;
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion test/IDE/coloring_comments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func emptyDocBlockComment3() {}
func malformedBlockComment(f : () throws -> ()) rethrows {}
// CHECK: <doc-comment-block>/**/</doc-comment-block>

// CHECK: <kw>func</kw> malformedBlockComment(f : () <kw>throws</kw> -> ()) <attr-builtin>rethrows</attr-builtin> {}
// CHECK: <kw>func</kw> malformedBlockComment(f : () <kw>throws</kw> -> ()) <kw>rethrows</kw> {}

//: playground doc comment line
func playgroundCommentLine(f : () throws -> ()) rethrows {}
Expand Down
2 changes: 2 additions & 0 deletions test/SourceKit/DocumentStructure/Inputs/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ enum MyEnum {
enum MySecondEnum {
case One = 1
}

func someFunc(input :Int?, completion: () throws -> Void) rethrows {}
40 changes: 39 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: 2065,
key.length: 2136,
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
key.substructure: [
{
Expand Down Expand Up @@ -1288,6 +1288,44 @@
]
}
]
},
{
key.kind: source.lang.swift.decl.function.free,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "someFunc(input:completion:)",
key.offset: 2066,
key.length: 69,
key.nameoffset: 2071,
key.namelength: 52,
key.bodyoffset: 2134,
key.bodylength: 0,
key.attributes: [
{
key.offset: 2124,
key.length: 8,
key.attribute: source.decl.attribute.rethrows
}
],
key.substructure: [
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "input",
key.offset: 2080,
key.length: 11,
key.typename: "Int?",
key.nameoffset: 2080,
key.namelength: 5
},
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "completion",
key.offset: 2093,
key.length: 29,
key.typename: "() throws -> Void",
key.nameoffset: 2093,
key.namelength: 10
}
]
}
],
key.diagnostics: [
Expand Down
40 changes: 39 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: 2065,
key.length: 2136,
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
key.substructure: [
{
Expand Down Expand Up @@ -1288,6 +1288,44 @@
]
}
]
},
{
key.kind: source.lang.swift.decl.function.free,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "someFunc(input:completion:)",
key.offset: 2066,
key.length: 69,
key.nameoffset: 2071,
key.namelength: 52,
key.bodyoffset: 2134,
key.bodylength: 0,
key.attributes: [
{
key.offset: 2124,
key.length: 8,
key.attribute: source.decl.attribute.rethrows
}
],
key.substructure: [
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "input",
key.offset: 2080,
key.length: 11,
key.typename: "Int?",
key.nameoffset: 2080,
key.namelength: 5
},
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "completion",
key.offset: 2093,
key.length: 29,
key.typename: "() throws -> Void",
key.nameoffset: 2093,
key.namelength: 10
}
]
}
],
key.diagnostics: [
Expand Down
40 changes: 39 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: 2065,
key.length: 2136,
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
key.substructure: [
{
Expand Down Expand Up @@ -1288,6 +1288,44 @@
]
}
]
},
{
key.kind: source.lang.swift.decl.function.free,
key.accessibility: source.lang.swift.accessibility.internal,
key.name: "someFunc(input:completion:)",
key.offset: 2066,
key.length: 69,
key.nameoffset: 2071,
key.namelength: 52,
key.bodyoffset: 2134,
key.bodylength: 0,
key.attributes: [
{
key.offset: 2124,
key.length: 8,
key.attribute: source.decl.attribute.rethrows
}
],
key.substructure: [
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "input",
key.offset: 2080,
key.length: 11,
key.typename: "Int?",
key.nameoffset: 2080,
key.namelength: 5
},
{
key.kind: source.lang.swift.decl.var.parameter,
key.name: "completion",
key.offset: 2093,
key.length: 29,
key.typename: "() throws -> Void",
key.nameoffset: 2093,
key.namelength: 10
}
]
}
],
key.diagnostics: [
Expand Down
3 changes: 3 additions & 0 deletions test/SourceKit/SyntaxMapData/Inputs/syntaxmap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ func testArgumentLabels(in class: Int, _ case: (_ default: Int) -> Void) -> (in:
let result: (in: Int, String) = (0, "test")
return something ? result : (in: 2, "foo")
}

// https://bugs.swift.org/browse/SR-9576
func someFunc(input :Int?, completion: () throws -> Void) rethrows {}
57 changes: 56 additions & 1 deletion test/SourceKit/SyntaxMapData/syntaxmap.swift.response
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
key.offset: 0,
key.length: 1049,
key.length: 1161,
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
key.syntaxmap: [
{
Expand Down Expand Up @@ -567,6 +567,61 @@
key.kind: source.lang.swift.syntaxtype.string,
key.offset: 1040,
key.length: 5
},
{
key.kind: source.lang.swift.syntaxtype.comment,
key.offset: 1050,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.comment.url,
key.offset: 1053,
key.length: 37
},
{
key.kind: source.lang.swift.syntaxtype.comment,
key.offset: 1090,
key.length: 1
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 1091,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 1096,
key.length: 8
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 1105,
key.length: 5
},
{
key.kind: source.lang.swift.syntaxtype.typeidentifier,
key.offset: 1112,
key.length: 3
},
{
key.kind: source.lang.swift.syntaxtype.identifier,
key.offset: 1118,
key.length: 10
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 1133,
key.length: 6
},
{
key.kind: source.lang.swift.syntaxtype.typeidentifier,
key.offset: 1143,
key.length: 4
},
{
key.kind: source.lang.swift.syntaxtype.keyword,
key.offset: 1149,
key.length: 8
}
]
}