Swift switch fallthrough matches wrong cases

Originator:widescape
Number:rdar://21216987 Date Originated:03-Jun-2015 09:49 AM
Status:Closed Resolved:No
Product:Developer Tools Product Version:iOS 8.3
Classification: Reproducible:
 
When a switch case has multiple cases, fallthrough continues to the next case that matches any of these multiple cases – instead of continuing to the next case matching the input.

Steps to Reproduce:
Execute the following code in playground in Xcode 6.3.2. If the output returns 3, you observed the error. If the output is 1, the error is not present.

let input = 1
var output = 0
switch input {
case 1, 2:
    output = 1
    fallthrough
case 2, 3:
    output = 2
    fallthrough
case 3:
    output = 3
default: break
}
output != 1 ? "\(output)? WAT!" : "Smooth"

Expected Results:
fallthrough should continue to the next case matching the input (1).

Actual Results:
fallthrough continues to the next case matching any of the cases of a multi-case.

Comments

Response from Apple Developer Relations

This issue behaves as intended based on the following:

This is intended behavior of the fallthrough statement, it falls through to the next statement without rematching the case.

We are now closing this bug report.


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!