Skip to content

Commit 17fc634

Browse files
committed
[Syntax] Classify contextual keywords used as decl attribute as contextual keyword
Previously, we classified e.g. final as an identifier, but it should be qualified as a contextual keyword. rdar://92463926 [swiftlang/swift-syntax#387]
1 parent 2f0ae44 commit 17fc634

File tree

4 files changed

+115
-2
lines changed

4 files changed

+115
-2
lines changed

lib/Parse/ParseDecl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3871,6 +3871,8 @@ bool Parser::parseDeclModifierList(DeclAttributes &Attributes,
38713871
if (Kind == DAK_Count)
38723872
break;
38733873

3874+
Tok.setKind(tok::contextual_keyword);
3875+
38743876
if (Kind == DAK_Actor) {
38753877
// If the next token is a startOfSwiftDecl, we are part of the modifier
38763878
// list and should consume the actor token (e.g, actor public class Foo)
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
{
2+
"kind": "SourceFile",
3+
"layout": [
4+
{
5+
"kind": "CodeBlockItemList",
6+
"layout": [
7+
{
8+
"kind": "CodeBlockItem",
9+
"layout": [
10+
{
11+
"kind": "ClassDecl",
12+
"layout": [
13+
null,
14+
{
15+
"kind": "ModifierList",
16+
"layout": [
17+
{
18+
"kind": "DeclModifier",
19+
"layout": [
20+
{
21+
"tokenKind": {
22+
"kind": "contextual_keyword",
23+
"text": "final"
24+
},
25+
"leadingTrivia": "\/\/ RUN: %swift-syntax-test -input-source-filename %s -serialize-raw-tree > %t\n\/\/ RUN: diff %t %S\/Inputs\/serialize_class_decl.json -u\n\n",
26+
"trailingTrivia": " ",
27+
"presence": "Present"
28+
},
29+
null,
30+
null,
31+
null
32+
],
33+
"presence": "Present"
34+
}
35+
],
36+
"presence": "Present"
37+
},
38+
{
39+
"tokenKind": {
40+
"kind": "kw_class"
41+
},
42+
"leadingTrivia": "",
43+
"trailingTrivia": " ",
44+
"presence": "Present"
45+
},
46+
{
47+
"tokenKind": {
48+
"kind": "identifier",
49+
"text": "Foo"
50+
},
51+
"leadingTrivia": "",
52+
"trailingTrivia": " ",
53+
"presence": "Present"
54+
},
55+
null,
56+
null,
57+
null,
58+
{
59+
"kind": "MemberDeclBlock",
60+
"layout": [
61+
{
62+
"tokenKind": {
63+
"kind": "l_brace"
64+
},
65+
"leadingTrivia": "",
66+
"trailingTrivia": "",
67+
"presence": "Present"
68+
},
69+
{
70+
"kind": "MemberDeclList",
71+
"layout": [],
72+
"presence": "Present"
73+
},
74+
{
75+
"tokenKind": {
76+
"kind": "r_brace"
77+
},
78+
"leadingTrivia": "",
79+
"trailingTrivia": "",
80+
"presence": "Present"
81+
}
82+
],
83+
"presence": "Present"
84+
}
85+
],
86+
"presence": "Present"
87+
},
88+
null,
89+
null
90+
],
91+
"presence": "Present"
92+
}
93+
],
94+
"presence": "Present"
95+
},
96+
{
97+
"tokenKind": {
98+
"kind": "eof",
99+
"text": ""
100+
},
101+
"leadingTrivia": "\n",
102+
"trailingTrivia": "",
103+
"presence": "Present"
104+
}
105+
],
106+
"presence": "Present"
107+
}

test/Syntax/Inputs/serialize_distributed_actor.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"layout": [
2020
{
2121
"tokenKind": {
22-
"kind": "identifier",
22+
"kind": "contextual_keyword",
2323
"text": "distributed"
2424
},
2525
"leadingTrivia": "\/\/ RUN: %swift-syntax-test -input-source-filename %s -serialize-raw-tree > %t\n\/\/ RUN: diff %t %S\/Inputs\/serialize_distributed_actor.json -u\n\n",
@@ -85,7 +85,7 @@
8585
"layout": [
8686
{
8787
"tokenKind": {
88-
"kind": "identifier",
88+
"kind": "contextual_keyword",
8989
"text": "distributed"
9090
},
9191
"leadingTrivia": "\n ",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %swift-syntax-test -input-source-filename %s -serialize-raw-tree > %t
2+
// RUN: diff %t %S/Inputs/serialize_class_decl.json -u
3+
4+
final class Foo {}

0 commit comments

Comments
 (0)