@@ -15,6 +15,7 @@ Previously pitched in:
15
15
- https://forums.swift.org/t/pitch-non-frozen-enumerations/68373
16
16
17
17
Revisions:
18
+ - Renamed the attribute to ` @nonexhaustive ` and ` @nonexhaustive(warn) ` respectively
18
19
- Re-focused this proposal on introducing a new ` @extensible ` attribute and
19
20
moved the language feature to a future direction
20
21
- Introduced a second annotation ` @nonExtensible ` to allow a migration path into
@@ -157,15 +158,15 @@ non-resilient Swift.
157
158
158
159
## Proposed solution
159
160
160
- We propose to introduce a new ` @extensible ` attribute that can be applied to
161
+ We propose to introduce a new ` @nonexhaustive ` attribute that can be applied to
161
162
enumerations to mark them as extensible. Such enums will behave the same way as
162
163
non-frozen enums from resilient Swift libraries.
163
164
164
165
An example of using the new attribute is below:
165
166
166
167
``` swift
167
168
/// Module A
168
- @extensible
169
+ @nonexhaustive
169
170
public enum PizzaFlavor {
170
171
case hawaiian
171
172
case pepperoni
@@ -188,28 +189,27 @@ case .cheese:
188
189
189
190
Code inside the same module or package can be thought of as one co-developed
190
191
unit of code. Inside the same module or package, switching exhaustively over an
191
- ` @extensible ` enum inside will not require an` @unknown default ` , and using
192
+ ` @nonexhaustive ` enum inside will not require an` @unknown default ` , and using
192
193
one will generate a warning.
193
194
194
- ### ` @extensible ` and ` @frozen `
195
+ ### ` @nonexhaustive ` and ` @frozen `
195
196
196
- An enum cannot be ` @frozen ` and ` @extensible ` at the same time. Thus, marking an
197
- enum both ` @extensible ` and ` @frozen ` is not allowed and will result in a
197
+ An enum cannot be ` @frozen ` and ` @nonexhaustive ` at the same time. Thus, marking an
198
+ enum both ` @nonexhaustive ` and ` @frozen ` is not allowed and will result in a
198
199
compiler error.
199
200
200
201
### API breaking checker
201
202
202
203
The behavior of ` swift package diagnose-api-breaking-changes ` is also updated
203
- to understand the new ` @extensible ` attribute.
204
+ to understand the new ` @nonexhaustive ` attribute.
204
205
205
- ### Staging in using ` @preEnumExtensibility `
206
+ ### Staging in using ` @nonexhaustive(warn) `
206
207
207
- We also propose adding a new ` @preEnumExtensibility ` attribute that can be used
208
- to mark enumerations as pre-existing to the ` @extensible ` attribute. This allows
209
- developers to mark existing public enumerations as ` @preEnumExtensibility ` in
210
- addition to ` @extensible ` . This is useful for developers that want to stage in
211
- changing an existing non-extensible enum to be extensible over multiple
212
- releases. Below is an example of how this can be used:
208
+ We also propose adding a new ` @nonexhaustive(warn) ` attribute that can be used
209
+ to mark enumerations as pre-existing to when they became extensible.This is
210
+ useful for developers that want to stage in changing an existing non-extensible
211
+ enum to be extensible over multiple releases. Below is an example of how this
212
+ can be used:
213
213
214
214
``` swift
215
215
// Package A
@@ -223,7 +223,7 @@ case .foo: break
223
223
}
224
224
225
225
// Package A wants to make the existing enum extensible
226
- @preEnumExtensibility @extensible
226
+ @nonexhaustive (warn)
227
227
public enum Foo {
228
228
case foo
229
229
}
@@ -234,7 +234,7 @@ case .foo: break
234
234
}
235
235
236
236
// Later Package A decides to extend the enum and releases a new major version
237
- @preEnumExtensibility @extensible
237
+ @nonexhaustive (warn)
238
238
public enum Foo {
239
239
case foo
240
240
case bar
@@ -246,7 +246,7 @@ case .foo: break
246
246
}
247
247
```
248
248
249
- While the ` @preEnumExtensibility ` attribute doesn't solve the need of requiring
249
+ While the ` @nonexhaustive(warn) ` attribute doesn't solve the need of requiring
250
250
a new major when a new case is added it allows developers to stage in changing
251
251
an existing non-extensible enum to become extensible in a future release by
252
252
surfacing a warning about this upcoming break early.
@@ -255,16 +255,16 @@ surfacing a warning about this upcoming break early.
255
255
256
256
### Resilient modules
257
257
258
- - Adding or removing the ` @extensible ` attribute has no-effect since it is the default in this language dialect.
259
- - Adding the ` @preEnumExtensibility ` attribute has no-effect since it only downgrades the error to a warning.
260
- - Removing the ` @preEnumExtensibility ` attribute is an API breaking since it upgrades the warning to an error again.
258
+ - Adding or removing the ` @nonexhaustive ` attribute has no-effect since it is the default in this language dialect.
259
+ - Adding the ` @nonexhaustive(warn) ` attribute has no-effect since it only downgrades the error to a warning.
260
+ - Removing the ` @nonexhaustive(warn) ` attribute is an API breaking since it upgrades the warning to an error again.
261
261
262
262
### Non-resilient modules
263
263
264
- - Adding the ` @extensible ` attribute is an API breaking change.
265
- - Removing the ` @extensible ` attribute is an API stable change.
266
- - Adding the ` @preEnumExtensibility ` attribute has no-effect since it only downgrades the error to a warning.
267
- - Removing the ` @preEnumExtensibility ` attribute is an API breaking since it upgrades the warning to an error again.
264
+ - Adding the ` @nonexhaustive ` attribute is an API breaking change.
265
+ - Removing the ` @nonexhaustive ` attribute is an API stable change.
266
+ - Adding the ` @nonexhaustive(warn) ` attribute has no-effect since it only downgrades the error to a warning.
267
+ - Removing the ` @nonexhaustive(warn) ` attribute is an API breaking since it upgrades the warning to an error again.
268
268
269
269
## ABI compatibility
270
270
@@ -314,6 +314,6 @@ enumerations to achieve the same effect.
314
314
315
315
### Different names for the attribute
316
316
317
- We considered different names for the attribute such as ` @nonFrozen ` ; however,
318
- we felt that ` @extensible ` communicates the idea of an extensible enum more
319
- clearly.
317
+ We considered different names for the attribute such as ` @nonFrozen ` or
318
+ ` @extensible ` ; however, we felt that ` @nonexhaustive ` communicates the idea of
319
+ an extensible enum more clearly.
0 commit comments