swift-book
swift-book copied to clipboard
Update documentation of enums for SE-0155
Location
At https://github.com/apple/swift-book/blob/main/TSPL.docc/ReferenceManual/SummaryOfTheGrammar.md#declarations
the definition of union-style-enum-case-clause
Description
The changes of SE-0155 don't seem to be documented in the official language specification yet.
For example, default value for union-style enums are not supported:
// https://github.com/apple/swift-evolution/blob/main/proposals/0155-normalize-enum-case-representation.md#default-parameter-values-for-enum-constructors
enum Animation {
case fadeIn(duration: TimeInterval = 0.3) // Okay!
}
let anim = Animation.fadeIn() // Great!
Correction
I'm not entirely sure, because I'm not an expert of the Swift language and don't know all about the history of the enum declaration spec. I checked the revision history of the language guide and couldn't find updates for SE-0155 or later proposals.
I think at least union-style-enum-case-clause
needs to be updated to match the proposed updates of the grammar:
union-style-enum-case = enum-case-name [enum-case-associated-value-clause];
enum-case-associated-value-clause = "(" ")"
| "(" enum-case-associated-value-list ")";
enum-case-associated-value-list = enum-associated-value-element
| enum-associated-value-element ","
enum-case-associated-value-list;
enum-case-associated-value-element = element-name type-annotation
[enum-case-element-default-value-clause]
| type
[enum-case-element-default-value-clause];
element-name = identifier;
enum-case-element-default-value-clause = "=" expression;
(If I'm not mistaken, the above proposal of SE-0155 references enum-associated-value-element
in enum-case-associated-value-list
, but only enum-case-associated-value-element
is defined (with an additional -case
part)
You're correct — the documentation hasn't been updated for SE-0155. That work was delayed because of the way the compiler implementation landed in smaller pieces, which made it hard to track whether the feature was implemented. I confirmed with Joe Groff in December 2022 that the implementation is done, and the SE proposal was updated to describe only what was implemented.
(For my future reference, that work is rdar://35041603)