Xcode 6.0 (6A267n): Switch over Swift boolean is not exhaustive

Originator:janoschhildebrand
Number:rdar://17851675 Date Originated:30-Jul-2014
Status:Duplicate of 16514545 (Closed) Resolved:8-Jun-2015
Product:Developer Tools Product Version:Xcode 6.0 (6A267n)
Classification:Enhancement Reproducible:Always
 
Summary:
The following Swift code does not compile:

let flag: Bool = true
switch flag {
case true:
    println("True")
case false:
    println("False")
}

The compiler complains that this switch statement is not exhaustive but this is obviously (hopefully) not true. An example is attached as a playground.

The underlying problem seems to be that the compiler can't easily check for exhaustiveness with structs (which Bool is). So either the compiler needs to become smarter (at least in this case) or Bool should be an enum.
Using an enum seems nicer to me in concept and you already solved the literal issue with 'nil' (literal for .None) but there might of course be other problems I am missing.

The obvious workaround for now is to add a dummy default clause but a nicer solution would be appreciated.

Steps to Reproduce:
1. Open the attached playground
2. Remove the default clause to see the compiler error

Expected Results:
The compiler should realise that 'true' and 'false' are the exhaustive list of possible cases for a boolean.

Actual Results:
The compiler does not currently do so.

Version:
Xcode Version 6.0 (6A267n)
Swift version 1.0 (swift-600.0.41.2.2)
OS X 10.10 (14A298i)

Comments


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!