Skip to content

Commit c74cf89

Browse files
authored
Merge pull request #22017 from marcelofabri/rethrows
[SR-9576][SourceKit] Fix syntax type when rethrows is present
2 parents 707a168 + d948823 commit c74cf89

File tree

8 files changed

+181
-5
lines changed

8 files changed

+181
-5
lines changed

lib/IDE/SyntaxModel.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,6 +1041,8 @@ bool ModelASTWalker::handleSpecialDeclAttribute(const DeclAttribute *D,
10411041
TokenNodes = TokenNodes.slice(I);
10421042
return true;
10431043
}
1044+
if (isa<RethrowsAttr>(D))
1045+
return true;
10441046
return false;
10451047
}
10461048

test/IDE/coloring_comments.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func emptyDocBlockComment3() {}
194194
func malformedBlockComment(f : () throws -> ()) rethrows {}
195195
// CHECK: <doc-comment-block>/**/</doc-comment-block>
196196

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

199199
//: playground doc comment line
200200
func playgroundCommentLine(f : () throws -> ()) rethrows {}

test/SourceKit/DocumentStructure/Inputs/main.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ enum MyEnum {
127127
enum MySecondEnum {
128128
case One = 1
129129
}
130+
131+
func someFunc(input :Int?, completion: () throws -> Void) rethrows {}

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2065,
3+
key.length: 2136,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1288,6 +1288,44 @@
12881288
]
12891289
}
12901290
]
1291+
},
1292+
{
1293+
key.kind: source.lang.swift.decl.function.free,
1294+
key.accessibility: source.lang.swift.accessibility.internal,
1295+
key.name: "someFunc(input:completion:)",
1296+
key.offset: 2066,
1297+
key.length: 69,
1298+
key.nameoffset: 2071,
1299+
key.namelength: 52,
1300+
key.bodyoffset: 2134,
1301+
key.bodylength: 0,
1302+
key.attributes: [
1303+
{
1304+
key.offset: 2124,
1305+
key.length: 8,
1306+
key.attribute: source.decl.attribute.rethrows
1307+
}
1308+
],
1309+
key.substructure: [
1310+
{
1311+
key.kind: source.lang.swift.decl.var.parameter,
1312+
key.name: "input",
1313+
key.offset: 2080,
1314+
key.length: 11,
1315+
key.typename: "Int?",
1316+
key.nameoffset: 2080,
1317+
key.namelength: 5
1318+
},
1319+
{
1320+
key.kind: source.lang.swift.decl.var.parameter,
1321+
key.name: "completion",
1322+
key.offset: 2093,
1323+
key.length: 29,
1324+
key.typename: "() throws -> Void",
1325+
key.nameoffset: 2093,
1326+
key.namelength: 10
1327+
}
1328+
]
12911329
}
12921330
],
12931331
key.diagnostics: [

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

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2065,
3+
key.length: 2136,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1288,6 +1288,44 @@
12881288
]
12891289
}
12901290
]
1291+
},
1292+
{
1293+
key.kind: source.lang.swift.decl.function.free,
1294+
key.accessibility: source.lang.swift.accessibility.internal,
1295+
key.name: "someFunc(input:completion:)",
1296+
key.offset: 2066,
1297+
key.length: 69,
1298+
key.nameoffset: 2071,
1299+
key.namelength: 52,
1300+
key.bodyoffset: 2134,
1301+
key.bodylength: 0,
1302+
key.attributes: [
1303+
{
1304+
key.offset: 2124,
1305+
key.length: 8,
1306+
key.attribute: source.decl.attribute.rethrows
1307+
}
1308+
],
1309+
key.substructure: [
1310+
{
1311+
key.kind: source.lang.swift.decl.var.parameter,
1312+
key.name: "input",
1313+
key.offset: 2080,
1314+
key.length: 11,
1315+
key.typename: "Int?",
1316+
key.nameoffset: 2080,
1317+
key.namelength: 5
1318+
},
1319+
{
1320+
key.kind: source.lang.swift.decl.var.parameter,
1321+
key.name: "completion",
1322+
key.offset: 2093,
1323+
key.length: 29,
1324+
key.typename: "() throws -> Void",
1325+
key.nameoffset: 2093,
1326+
key.namelength: 10
1327+
}
1328+
]
12911329
}
12921330
],
12931331
key.diagnostics: [

test/SourceKit/DocumentStructure/structure.swift.response

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 2065,
3+
key.length: 2136,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.substructure: [
66
{
@@ -1288,6 +1288,44 @@
12881288
]
12891289
}
12901290
]
1291+
},
1292+
{
1293+
key.kind: source.lang.swift.decl.function.free,
1294+
key.accessibility: source.lang.swift.accessibility.internal,
1295+
key.name: "someFunc(input:completion:)",
1296+
key.offset: 2066,
1297+
key.length: 69,
1298+
key.nameoffset: 2071,
1299+
key.namelength: 52,
1300+
key.bodyoffset: 2134,
1301+
key.bodylength: 0,
1302+
key.attributes: [
1303+
{
1304+
key.offset: 2124,
1305+
key.length: 8,
1306+
key.attribute: source.decl.attribute.rethrows
1307+
}
1308+
],
1309+
key.substructure: [
1310+
{
1311+
key.kind: source.lang.swift.decl.var.parameter,
1312+
key.name: "input",
1313+
key.offset: 2080,
1314+
key.length: 11,
1315+
key.typename: "Int?",
1316+
key.nameoffset: 2080,
1317+
key.namelength: 5
1318+
},
1319+
{
1320+
key.kind: source.lang.swift.decl.var.parameter,
1321+
key.name: "completion",
1322+
key.offset: 2093,
1323+
key.length: 29,
1324+
key.typename: "() throws -> Void",
1325+
key.nameoffset: 2093,
1326+
key.namelength: 10
1327+
}
1328+
]
12911329
}
12921330
],
12931331
key.diagnostics: [

test/SourceKit/SyntaxMapData/Inputs/syntaxmap.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@ func testArgumentLabels(in class: Int, _ case: (_ default: Int) -> Void) -> (in:
5454
let result: (in: Int, String) = (0, "test")
5555
return something ? result : (in: 2, "foo")
5656
}
57+
58+
// https://bugs.swift.org/browse/SR-9576
59+
func someFunc(input :Int?, completion: () throws -> Void) rethrows {}

test/SourceKit/SyntaxMapData/syntaxmap.swift.response

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
key.offset: 0,
3-
key.length: 1049,
3+
key.length: 1161,
44
key.diagnostic_stage: source.diagnostic.stage.swift.parse,
55
key.syntaxmap: [
66
{
@@ -567,6 +567,61 @@
567567
key.kind: source.lang.swift.syntaxtype.string,
568568
key.offset: 1040,
569569
key.length: 5
570+
},
571+
{
572+
key.kind: source.lang.swift.syntaxtype.comment,
573+
key.offset: 1050,
574+
key.length: 3
575+
},
576+
{
577+
key.kind: source.lang.swift.syntaxtype.comment.url,
578+
key.offset: 1053,
579+
key.length: 37
580+
},
581+
{
582+
key.kind: source.lang.swift.syntaxtype.comment,
583+
key.offset: 1090,
584+
key.length: 1
585+
},
586+
{
587+
key.kind: source.lang.swift.syntaxtype.keyword,
588+
key.offset: 1091,
589+
key.length: 4
590+
},
591+
{
592+
key.kind: source.lang.swift.syntaxtype.identifier,
593+
key.offset: 1096,
594+
key.length: 8
595+
},
596+
{
597+
key.kind: source.lang.swift.syntaxtype.identifier,
598+
key.offset: 1105,
599+
key.length: 5
600+
},
601+
{
602+
key.kind: source.lang.swift.syntaxtype.typeidentifier,
603+
key.offset: 1112,
604+
key.length: 3
605+
},
606+
{
607+
key.kind: source.lang.swift.syntaxtype.identifier,
608+
key.offset: 1118,
609+
key.length: 10
610+
},
611+
{
612+
key.kind: source.lang.swift.syntaxtype.keyword,
613+
key.offset: 1133,
614+
key.length: 6
615+
},
616+
{
617+
key.kind: source.lang.swift.syntaxtype.typeidentifier,
618+
key.offset: 1143,
619+
key.length: 4
620+
},
621+
{
622+
key.kind: source.lang.swift.syntaxtype.keyword,
623+
key.offset: 1149,
624+
key.length: 8
570625
}
571626
]
572627
}

0 commit comments

Comments
 (0)