Skip to content

Commit bc9dbf0

Browse files
authored
Rename @extensible to @nonexhaustive and @nonexhaustive(warn) (swiftlang#2897)
1 parent af6f8a0 commit bc9dbf0

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

proposals/0487-extensible-enums.md

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Previously pitched in:
1515
- https://forums.swift.org/t/pitch-non-frozen-enumerations/68373
1616

1717
Revisions:
18+
- Renamed the attribute to `@nonexhaustive` and `@nonexhaustive(warn)` respectively
1819
- Re-focused this proposal on introducing a new `@extensible` attribute and
1920
moved the language feature to a future direction
2021
- Introduced a second annotation `@nonExtensible` to allow a migration path into
@@ -157,15 +158,15 @@ non-resilient Swift.
157158

158159
## Proposed solution
159160

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
161162
enumerations to mark them as extensible. Such enums will behave the same way as
162163
non-frozen enums from resilient Swift libraries.
163164

164165
An example of using the new attribute is below:
165166

166167
```swift
167168
/// Module A
168-
@extensible
169+
@nonexhaustive
169170
public enum PizzaFlavor {
170171
case hawaiian
171172
case pepperoni
@@ -188,28 +189,27 @@ case .cheese:
188189

189190
Code inside the same module or package can be thought of as one co-developed
190191
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
192193
one will generate a warning.
193194

194-
### `@extensible` and `@frozen`
195+
### `@nonexhaustive` and `@frozen`
195196

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
198199
compiler error.
199200

200201
### API breaking checker
201202

202203
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.
204205

205-
### Staging in using `@preEnumExtensibility`
206+
### Staging in using `@nonexhaustive(warn)`
206207

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:
213213

214214
```swift
215215
// Package A
@@ -223,7 +223,7 @@ case .foo: break
223223
}
224224

225225
// Package A wants to make the existing enum extensible
226-
@preEnumExtensibility @extensible
226+
@nonexhaustive(warn)
227227
public enum Foo {
228228
case foo
229229
}
@@ -234,7 +234,7 @@ case .foo: break
234234
}
235235

236236
// Later Package A decides to extend the enum and releases a new major version
237-
@preEnumExtensibility @extensible
237+
@nonexhaustive(warn)
238238
public enum Foo {
239239
case foo
240240
case bar
@@ -246,7 +246,7 @@ case .foo: break
246246
}
247247
```
248248

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
250250
a new major when a new case is added it allows developers to stage in changing
251251
an existing non-extensible enum to become extensible in a future release by
252252
surfacing a warning about this upcoming break early.
@@ -255,16 +255,16 @@ surfacing a warning about this upcoming break early.
255255

256256
### Resilient modules
257257

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.
261261

262262
### Non-resilient modules
263263

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.
268268

269269
## ABI compatibility
270270

@@ -314,6 +314,6 @@ enumerations to achieve the same effect.
314314

315315
### Different names for the attribute
316316

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

Comments
 (0)