Skip to content

Commit 1b41972

Browse files
committed
[Syntax] Use FunctionSignature for initializer declarations.
Initializer declarations were missing support for `async`, in part because they deplicated most of the `FunctionSignature` production. Instead, use `FunctionSignature` consistently and let the presence of a result type be a semantic error.
1 parent 2f5b638 commit 1b41972

File tree

4 files changed

+129
-118
lines changed

4 files changed

+129
-118
lines changed

test/Parse/init_deinit.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
struct FooStructConstructorA {
44
init // expected-error {{expected '('}}
5+
// expected-error@-1{{initializer requires a body}}
56
}
67

78
struct FooStructConstructorB {
@@ -10,10 +11,17 @@ struct FooStructConstructorB {
1011

1112
struct FooStructConstructorC {
1213
init {} // expected-error {{expected '('}}{{7-7=()}}
14+
// expected-note@-1{{'init()' previously declared here}}
1315
init<T> {} // expected-error {{expected '('}} {{10-10=()}}
16+
// expected-error@-1{{generic parameter 'T' is not used in function signature}}
1417
init? { self.init() } // expected-error {{expected '('}} {{8-8=()}}
18+
// expected-error@-1{{invalid redeclaration of 'init()'}}
1519
}
1620

21+
struct FooStructConstructorD {
22+
init() -> FooStructConstructorD { }
23+
// expected-error@-1{{initializers cannot have a result type}}
24+
}
1725

1826
struct FooStructDeinitializerA {
1927
deinit // expected-error {{expected '{' for deinitializer}}

test/Parse/recovery.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ struct InitializerWithNameAndParam {
699699
struct InitializerWithLabels {
700700
init c d: Int {}
701701
// expected-error @-1 {{expected '(' for initializer parameters}}
702+
// expected-error @-2 {{initializer requires a body}}
702703
}
703704

704705
// rdar://20337695

test/Syntax/Inputs/serialize_main_actor.json

Lines changed: 119 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -65,169 +65,177 @@
6565
null,
6666
null,
6767
{
68-
"kind": "ParameterClause",
68+
"kind": "FunctionSignature",
6969
"layout": [
7070
{
71-
"tokenKind": {
72-
"kind": "l_paren"
73-
},
74-
"leadingTrivia": "",
75-
"trailingTrivia": "",
76-
"presence": "Present"
77-
},
78-
{
79-
"kind": "FunctionParameterList",
71+
"kind": "ParameterClause",
8072
"layout": [
8173
{
82-
"kind": "FunctionParameter",
74+
"tokenKind": {
75+
"kind": "l_paren"
76+
},
77+
"leadingTrivia": "",
78+
"trailingTrivia": "",
79+
"presence": "Present"
80+
},
81+
{
82+
"kind": "FunctionParameterList",
8383
"layout": [
84-
null,
85-
{
86-
"tokenKind": {
87-
"kind": "kw__"
88-
},
89-
"leadingTrivia": "",
90-
"trailingTrivia": " ",
91-
"presence": "Present"
92-
},
93-
{
94-
"tokenKind": {
95-
"kind": "identifier",
96-
"text": "foo"
97-
},
98-
"leadingTrivia": "",
99-
"trailingTrivia": "",
100-
"presence": "Present"
101-
},
10284
{
103-
"tokenKind": {
104-
"kind": "colon"
105-
},
106-
"leadingTrivia": "",
107-
"trailingTrivia": " ",
108-
"presence": "Present"
109-
},
110-
{
111-
"kind": "AttributedType",
85+
"kind": "FunctionParameter",
11286
"layout": [
11387
null,
11488
{
115-
"kind": "AttributeList",
89+
"tokenKind": {
90+
"kind": "kw__"
91+
},
92+
"leadingTrivia": "",
93+
"trailingTrivia": " ",
94+
"presence": "Present"
95+
},
96+
{
97+
"tokenKind": {
98+
"kind": "identifier",
99+
"text": "foo"
100+
},
101+
"leadingTrivia": "",
102+
"trailingTrivia": "",
103+
"presence": "Present"
104+
},
105+
{
106+
"tokenKind": {
107+
"kind": "colon"
108+
},
109+
"leadingTrivia": "",
110+
"trailingTrivia": " ",
111+
"presence": "Present"
112+
},
113+
{
114+
"kind": "AttributedType",
116115
"layout": [
116+
null,
117117
{
118-
"kind": "CustomAttribute",
118+
"kind": "AttributeList",
119119
"layout": [
120120
{
121-
"tokenKind": {
122-
"kind": "at_sign"
123-
},
124-
"leadingTrivia": "",
125-
"trailingTrivia": "",
126-
"presence": "Present"
127-
},
128-
{
129-
"kind": "SimpleTypeIdentifier",
121+
"kind": "CustomAttribute",
130122
"layout": [
131123
{
132124
"tokenKind": {
133-
"kind": "identifier",
134-
"text": "MainActor"
125+
"kind": "at_sign"
135126
},
136127
"leadingTrivia": "",
137-
"trailingTrivia": " ",
128+
"trailingTrivia": "",
129+
"presence": "Present"
130+
},
131+
{
132+
"kind": "SimpleTypeIdentifier",
133+
"layout": [
134+
{
135+
"tokenKind": {
136+
"kind": "identifier",
137+
"text": "MainActor"
138+
},
139+
"leadingTrivia": "",
140+
"trailingTrivia": " ",
141+
"presence": "Present"
142+
},
143+
null
144+
],
138145
"presence": "Present"
139146
},
147+
null,
148+
null,
140149
null
141150
],
142151
"presence": "Present"
143-
},
144-
null,
145-
null,
146-
null
152+
}
147153
],
148154
"presence": "Present"
149-
}
150-
],
151-
"presence": "Present"
152-
},
153-
{
154-
"kind": "FunctionType",
155-
"layout": [
156-
{
157-
"tokenKind": {
158-
"kind": "l_paren"
159-
},
160-
"leadingTrivia": "",
161-
"trailingTrivia": "",
162-
"presence": "Present"
163-
},
164-
{
165-
"kind": "TupleTypeElementList",
166-
"layout": [],
167-
"presence": "Present"
168-
},
169-
{
170-
"tokenKind": {
171-
"kind": "r_paren"
172-
},
173-
"leadingTrivia": "",
174-
"trailingTrivia": " ",
175-
"presence": "Present"
176-
},
177-
null,
178-
null,
179-
{
180-
"tokenKind": {
181-
"kind": "arrow"
182-
},
183-
"leadingTrivia": "",
184-
"trailingTrivia": " ",
185-
"presence": "Present"
186155
},
187156
{
188-
"kind": "SimpleTypeIdentifier",
157+
"kind": "FunctionType",
189158
"layout": [
190159
{
191160
"tokenKind": {
192-
"kind": "identifier",
193-
"text": "Void"
161+
"kind": "l_paren"
194162
},
195163
"leadingTrivia": "",
196164
"trailingTrivia": "",
197165
"presence": "Present"
198166
},
199-
null
167+
{
168+
"kind": "TupleTypeElementList",
169+
"layout": [],
170+
"presence": "Present"
171+
},
172+
{
173+
"tokenKind": {
174+
"kind": "r_paren"
175+
},
176+
"leadingTrivia": "",
177+
"trailingTrivia": " ",
178+
"presence": "Present"
179+
},
180+
null,
181+
null,
182+
{
183+
"tokenKind": {
184+
"kind": "arrow"
185+
},
186+
"leadingTrivia": "",
187+
"trailingTrivia": " ",
188+
"presence": "Present"
189+
},
190+
{
191+
"kind": "SimpleTypeIdentifier",
192+
"layout": [
193+
{
194+
"tokenKind": {
195+
"kind": "identifier",
196+
"text": "Void"
197+
},
198+
"leadingTrivia": "",
199+
"trailingTrivia": "",
200+
"presence": "Present"
201+
},
202+
null
203+
],
204+
"presence": "Present"
205+
}
200206
],
201207
"presence": "Present"
202208
}
203209
],
204210
"presence": "Present"
205-
}
211+
},
212+
null,
213+
null,
214+
null
206215
],
207216
"presence": "Present"
208-
},
209-
null,
210-
null,
211-
null
217+
}
212218
],
213219
"presence": "Present"
220+
},
221+
{
222+
"tokenKind": {
223+
"kind": "r_paren"
224+
},
225+
"leadingTrivia": "",
226+
"trailingTrivia": " ",
227+
"presence": "Present"
214228
}
215229
],
216230
"presence": "Present"
217231
},
218-
{
219-
"tokenKind": {
220-
"kind": "r_paren"
221-
},
222-
"leadingTrivia": "",
223-
"trailingTrivia": " ",
224-
"presence": "Present"
225-
}
232+
null,
233+
null,
234+
null
226235
],
227236
"presence": "Present"
228237
},
229238
null,
230-
null,
231239
{
232240
"kind": "CodeBlock",
233241
"layout": [

utils/gyb_syntax_support/DeclNodes.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,7 @@
455455
is_optional=True),
456456
Child('GenericParameterClause', kind='GenericParameterClause',
457457
is_optional=True),
458-
Child('Parameters', kind='ParameterClause'),
459-
Child('ThrowsOrRethrowsKeyword', kind='Token',
460-
is_optional=True,
461-
token_choices=[
462-
'ThrowsToken',
463-
'RethrowsToken',
464-
]),
458+
Child('Signature', kind='FunctionSignature'),
465459
Child('GenericWhereClause', kind='GenericWhereClause',
466460
is_optional=True),
467461
# the body is not necessary inside a protocol definition

0 commit comments

Comments
 (0)