Enum X { case x(((((Int, String))))) } is the same as ... case x(Int, String) ... except when creating

enum X {
    case x(((((Int, String)))))
}

is the same as

enum X {
    case x(Int, String)
}

except when creating a X:

let a = X.x((123, "ABC"))

vs.

let a = X.x(123, "ABC")

Other than this, both case behave the same elsewhere (switch/case let, if case let, guard case let). Since Swift don't allow single element tuple, ((T)) is same as T. Shouldn't the compile be consistent and make both the same? So both use:

let a = X.x(123, "ABC")

So that a typealias can be used to define the enum associate value?

typealias G = (Int, String)

enum X {
    case x(G)
}

It appears the compiler is special case treating single element tuple expression as just the type, so should enum associated value be the same?

An enum case payload behaves like a function parameter list and not like a single tuple value. For this reason wrapping the payload in parens changes the behavior - you now have a parameter list with a single parameter.

4 Likes