swiftlang / swift-book

The Swift Programming Language book
Apache License 2.0
1.76k stars 162 forks source link

Error in Grammar of an enumeration declaration #265

Open tadbyt opened 10 months ago

tadbyt commented 10 months ago

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.