[swift-users] Expression pattern cannot be a named tuple constant

Neil Faiman neil.swift at faiman.org
Mon Jul 4 16:56:21 CDT 2016


(Resending — this didn’t get any responses when I sent it a month ago.)

Swift 2.2 in Xcode 7.3.1.

Apparently you cannot use a named tuple constant as an expression pattern in a case label.

func test(x: Int, y: Int) -> Int {
   let int_1 = 1
   switch x {
   case 0:
       return 0
   case int_1:
       return 1
   default:
       break
   }

   let int_1_1: (Int, Int) = (1, 1)
   switch (x, y) {
   case (0, 0):
       return 0
   case int_1_1:	// <<<<
       return 1
   default:
       return -1
   }
}

error: expression pattern of type '(Int, Int)' cannot match values of type '(Int, Int)'
   case int_1_1:
        ^~~~~~~

The error message is particularly amusing.

	- Neil Faiman


More information about the swift-users mailing list