Swift 2 can't tell if switch statements are exhaustive with enum tuples.

Originator:atomicbird
Number:rdar://22622635 Date Originated:2015-09-08
Status:Open Resolved:
Product:Xcode Product Version:7.0b6
Classification: Reproducible:
 
Summary:
When using a switch statement in Swift 2.0 on a tuple of two enumerations, it can't accurately determine whether the switch is exhaustive. It incorrectly reports that the switch is not exhaustive even when it is.

Steps to Reproduce:
Try this code, for example in a Swift playground:

import UIKit

enum Foo {
    case A
    case B
    case C
}

enum Bar {
    case D
    case E
}

func doSomething(foo:Foo, bar:Bar) {
    switch(foo, bar) {
    case (.A, .D):
        break
    case (.A, .E):
        break
    case (.B, _):
        break
    case (.C, _):
        break
    }
}


Expected Results:
Since the switch statement covers every possible combination of values, it would be accepted by the compiler.

Actual Results:
The Swift compiler reports "error: switch must be exhaustive, consider adding a default clause".

Version:
Xcode Version 7.0 beta 6 (7A192o)
OS X 10.10.5 (14F27)

Notes:
Sample playground attached.


Configuration:


Attachments:
'MyPlayground.playground.zip' was successfully uploaded.

Comments

Also happens with Bool Tupels

func switchOverBoolTuple(boolTuple: (Bool, Bool)) {
  switch boolTuple {
     case (true, true):
       break
     case (true, false):
       break
     case (false, _):
       break
   }
}

By timbogeld at Oct. 1, 2015, 7:02 p.m. (reply...)

Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!