Enum case labels are ignored in "case let" statements
| Originator: | pyry.jahkola | ||
| Number: | rdar://20135489 | Date Originated: | 2015-03-12 |
| Status: | Closed | Resolved: | 2015-06-16 |
| Product: | Developer Tools | Product Version: | |
| Classification: | Other Bug | Reproducible: | Always |
Fixed in Swift 2 beta 1.
Summary:
Enums can have associated values and associated values can have labels like tuples have labels. However, those labels do little to catch silly programmer errors in switch statements where enums are most commonly used.
In particular, if the enum happens to have multiple associated values of the same type with labels, the Swift compiler happily accepts those labels in any order in a "case let" statement.
It would be better if doing so would be an error.
It would be A LOT better if permuting the order of labelled associated values would be allowed but the compiler swizzled the values to their correct counterparts in a "case let".
Steps to Reproduce:
Run the code:
```
enum MyEnum {
case Case(one: String, two: String)
}
switch MyEnum.Case(one: "expected", two: "unexpected") {
case let .Case(two: _, one: x):
println(x) // prints "unexpected"
}
```
Expected Results:
I would expect either:
1. A compiler error stating that the labels are in wrong order
OR, better yet:
2. The code to run and print "expected". I just happened to grab the associated values in another order!
Actual Results:
The code prints the word "unexpected". Which I very likely an error.
Version:
Happens in both:
- Xcode 6.2 (6C131e)
- Xcode 6.3 beta 2 (6D532l)
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!