swift-book icon indicating copy to clipboard operation
swift-book copied to clipboard

Error in Grammar of an enumeration declaration

Open tadbyt opened this issue 1 year ago • 0 comments

Location

https://docs.swift.org/swift-book/documentation/the-swift-programming-language/declarations#Enumeration-Declaration https://docs.swift.org/swift-book/documentation/the-swift-programming-language/summaryofthegrammar#Declarations

Description

In both instances of the Grammar of an enumeration declaration, the declaration for associated values is given as a tuple-type. The problem is that a tuple-type requires at least two entries and an enumeration case is allowed a single associated value.

Also, there is a conflict between the text in the Enumerations with Cases of a Raw-Value Type and the raw-value-literal production in the grammar. The latter allows a Boolean value, but the former does not allow Bool to be a raw value type. Neither is Bool allowed as a raw value type in the Raw Values subsection of Enumerations in the Language Guide. Per Xcode, Bool is not a valid raw value type.

Correction

Replace the existing union-style-enum-case production with:

union-style-enum-caseenum-case-name associated-values? associated-values( tuple-type-element-list )

With respect to the second issue, remove boolean-literal as an alternative from the raw-value-literal production.

tadbyt avatar Feb 04 '24 01:02 tadbyt