Swift switch/case seemingly has an off-by-one bug in UInt16 range matching
| Originator: | antonio.malara | ||
| Number: | rdar://23101392 | Date Originated: | 14 oct 2015 |
| Status: | Open | Resolved: | no |
| Product: | Product Version: | ||
| Classification: | Reproducible: |
Summary:
I was trying to switch over a UInt16 variable, and i couldn't get a range case statement to include 0xFFFF.
(this is maybe duplicate of rdar://19779978)
Steps to Reproduce:
i can always reproduce it with this repl session
Minene:~ willy$ swift
Welcome to Apple Swift version 2.0 (700.0.59 700.0.72). Type :help for assistance.
1> let x : UInt16 = 0
x: UInt16 = 0
2> switch x {
3. case 0x0000 ..< 0xffff:
4. print("dah")
5. }
repl.swift:5:1: error: switch must be exhaustive, consider adding a default clause
}
^
2> ^D
Minene:~ willy$ swift
Expected Results:
no errors
Actual Results:
Version:
Apple Swift version 2.0 (700.0.59 700.0.72).
Notes:
Configuration:
Attachments:
this another puzzling repl session
1> let x : UInt16 = 0
x: UInt16 = 0
2> switch x {
3. case 0x0000 ... 0xfffe:
4. print("wat")
5. case 0xffff:
6. print("wat2")
7. }
repl.swift:7:1: error: switch must be exhaustive, consider adding a default clause
}
^
2> switch x {
3. case 0x0000 ..< 0xfffe:
4. print("dah")
5. case 0xfffe:
6. print("wat")
7. case 0xffff:
8. print("wat2")
9. }
10.
repl.swift:9:1: error: switch must be exhaustive, consider adding a default clause
}
^
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!