Proposal: Support constant expressions in enum case raw values

Example:

enum A : [Int] {
    case B = [1,2,3]
}

Currently, the following error occurs: "raw value for enum case must be a literal"

A more typically requested example is “case B = 1+2”.

Swift currently has no notion of a “constant expression”. Once it does, implementing this sort of feature is reasonable, but we need to design out “computed lets” and “pure functions” first.

-Chris

···

On Dec 31, 2015, at 1:46 PM, Amir Michail via swift-evolution <swift-evolution@swift.org> wrote:

Example:

enum A : [Int] {
   case B = [1,2,3]
}

Currently, the following error occurs: "raw value for enum case must be a literal”

1 Like