You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -34,8 +34,8 @@ Other comma-separated lists in the language could also benefit from the flexibil
34
34
let numbers = [1, 2, 0, 3, 4, 0, 0, 5]
35
35
36
36
let subsequences = numbers.split(
37
-
separator: 0,
38
-
//maxSplits: 1
37
+
separator: 0,
38
+
// maxSplits: 1
39
39
) ❌ Unexpected ',' separator
40
40
```
41
41
@@ -52,65 +52,122 @@ This proposal adds support for trailing commas in comma-separated lists when the
52
52
- Tuples and tuple patterns.
53
53
54
54
```swift
55
-
(1, 2,)
56
-
let block: (Int, Int,) ->Void= { (a, b,) in }
57
-
let (a, b,) = (1, 2,)
58
-
for (a, b,) inzip(s1, s2) { }
55
+
56
+
let velocity = (
57
+
1.66007664274403694e-03,
58
+
7.69901118419740425e-03,
59
+
6.90460016972063023e-05,
60
+
)
61
+
62
+
let (
63
+
velocityX,
64
+
velocityY,
65
+
velocityZ,
66
+
) = velocity
67
+
59
68
```
60
69
61
70
- Parameter and argument lists of initializers, functions, enum associated values, expression macros, attributes, and availability specs.
62
71
63
72
```swift
64
73
65
-
funcfoo(a: Int, b: Int,) { }
74
+
funcfoo(
75
+
input1: Int=0,
76
+
input2: Int=0,
77
+
) { }
66
78
67
-
foo(a: 1, b: 1,)
79
+
foo(
80
+
input1: 1,
81
+
input2: 1,
82
+
)
68
83
69
84
structS {
70
-
init(a: Int, b: Int,) { }
85
+
init(
86
+
input1: Int=0,
87
+
input2: Int=0,
88
+
) { }
71
89
}
72
90
73
91
enumE {
74
-
casefoo(a: Int, b: Int,)
92
+
casefoo(
93
+
input1: Int = 0,
94
+
input2: Int = 0,
95
+
)
75
96
}
76
97
77
-
@Foo(1, 2, 3,)
98
+
@Foo(
99
+
"input 1",
100
+
"input 2",
101
+
"input 3",
102
+
)
78
103
structS { }
79
104
80
-
f(_: @foo(1, 2,) Int)
81
-
82
-
#foo(1, 2,)
105
+
#foo(
106
+
"input 1",
107
+
"input 2",
108
+
"input 3",
109
+
)
83
110
84
111
structS {
85
-
#foo(1, 2,)
112
+
#foo(
113
+
"input 1",
114
+
"input 2",
115
+
"input 3",
116
+
)
86
117
}
87
118
88
-
if#unavailable(iOS15, watchOS9,) { }
119
+
if#unavailable(
120
+
iOS15,
121
+
watchOS9,
122
+
) { }
89
123
90
124
```
91
125
- Subscripts, including key path subscripts.
92
126
93
127
```swift
94
-
let value = m[x, y,]
128
+
let value = m[
129
+
x,
130
+
y,
131
+
]
95
132
96
-
let keyPath = \Foo.bar[x,y,]
133
+
let keyPath = \Foo.bar[
134
+
x,
135
+
y,
136
+
]
97
137
98
-
f(\.[x,y,])
138
+
f(\.[
139
+
x,
140
+
y,
141
+
])
99
142
```
100
143
101
144
-`if`, `guard` and `while` condition lists.
102
145
103
146
```swift
104
-
if a, b, { }
105
-
while a, b, { }
106
-
guard a, b, else { }
147
+
if
148
+
condition1,
149
+
condition2,
150
+
{ }
151
+
152
+
while
153
+
condition1,
154
+
condition2,
155
+
{ }
156
+
157
+
guard
158
+
condition1,
159
+
condition2,
160
+
else { }
107
161
```
108
162
109
163
-`switch` case labels.
110
164
111
165
```swift
112
166
switch number {
113
-
case1, 2,:
167
+
case
168
+
1,
169
+
2,
170
+
:
114
171
...
115
172
default:
116
173
..
@@ -120,25 +177,44 @@ switch number {
120
177
- Closure capture lists.
121
178
122
179
```swift
123
-
{ [a, b,] in }
180
+
{ [
181
+
capturedValue1,
182
+
capturedValue2,
183
+
] in
184
+
}
124
185
```
125
186
126
187
- Inheritance clauses.
127
188
128
189
```swift
129
-
structS: P1, P2, P3, { }
190
+
structS:
191
+
P1,
192
+
P2,
193
+
P3,
194
+
{ }
130
195
```
131
196
132
197
- Generic parameters.
133
198
134
199
```swift
135
-
structS<T1, T2, T3,> { }
200
+
structS<
201
+
T1,
202
+
T2,
203
+
T3,
204
+
> { }
136
205
```
137
206
138
207
- Generic `where` clauses.
139
208
140
209
```swift
141
-
structS<T1, T2, T3> where T1:P1, T2:P2, { }
210
+
structS<
211
+
T1,
212
+
T2,
213
+
T3
214
+
> where
215
+
T1:P1,
216
+
T2:P2,
217
+
{ }
142
218
```
143
219
144
220
- String interpolation
@@ -157,27 +233,34 @@ Enum case label lists:
157
233
158
234
```swift
159
235
enumE {
160
-
casea, b, c, // ❌ Expected identifier after comma in enum 'case' declaration
236
+
case
237
+
a,
238
+
b,
239
+
c, // ❌ Expected identifier after comma in enum 'case' declaration
161
240
}
162
241
```
163
242
164
243
Inheritance clauses for associated types in a protocol declaration:
165
244
166
245
```swift
167
246
protocolFoo {
168
-
associatedtypeT: P1, P2, // ❌ Expected type
247
+
associatedtypeT:
248
+
P1,
249
+
P2, // ❌ Expected type
169
250
}
170
251
```
171
252
172
253
Generic `where` clauses for initializers and functions in a protocol declaration:
173
254
174
255
```swift
175
256
protocolFoo {
176
-
funcf<T1, T2>(a: T1, b: T2) where T1:P1, T2:P2, // ❌ Expected type
257
+
funcf<T1, T2>(a: T1, b: T2) where
258
+
T1:P1,
259
+
T2:P2, // ❌ Expected type
177
260
}
178
261
```
179
262
180
-
Trailing commas will be allowed in single-element lists but not in zero-element lists, since the trailing comma is actually attached to the last element. Supporting a zero-element list would require supporting _leading_commas, which isn't what this proposal is about.
263
+
Trailing commas will be allowed in single-element lists but not in zero-element lists, since the trailing comma is actually attached to the last element. Supporting a zero-element list would require supporting _leading_commas, which isn't what this proposal is about.
0 commit comments