Switch ranges should work predictably with float values
| Originator: | M.Garrett.Larson | ||
| Number: | rdar://17234391 | Date Originated: | 09-Jun-2014 |
| Status: | Open | Resolved: | |
| Product: | Swift | Product Version: | |
| Classification: | Reproducible: |
Summary:
Ranges constructed with two dots do not match float values in the desired way. Ideally the match would be performed using comparisons, but a compile-time error seems appropriate if it's decided that floats should not be matched against integral ranges. The current behavior could be a source for many subtle bugs.
Steps to Reproduce:
switch(1.1) {
case 0..1: println("0 <= x < 1")
case 1..2: println("1 <= x < 2")
case 2..3: println("2 <= x < 3")
default: println("x not contained in 0..3")
}
Expected Results:
=> "1 <= x < 2"
Actual Results:
=> "2 <= x < 3"
Version:
Xcode 6.0 6A215I
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!