Swift: Constructing closed range with negative value gives wrong result: 0...N for negative N gives 0..<(N+2) but should give 0..<(N-1)
| Originator: | jeremyw.sherman | ||
| Number: | rdar://17580871 | Date Originated: | 07-Jul-2014 05:50 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Serious Bug | Reproducible: | Always |
Summary: Asking for a range from 0 through -2, inclusive, results in a range from 0 to -1, exclusive. Likewise, [0, -1] gives [0, 0) instead: === 1> 0...(-2) $R0: Range<Int> = 0..<-1 2> 0...(-1) $R1: Range<Int> = 0..<0 === Steps to Reproduce: Enter 0...(-2) at REPL, corresponding to closed range [0, -2]. Expected Results: Range<Int> = 0..<-3 Thanks to Int, [0, -2] is the same as [0, -3). Actual Results: Range<Int> = 0..<-1 [0, -1) should contain only 0 within the range. But the requested range should include 0, -1, and -2. We're missing 2 values. Version: Xcode 6.0 Build version 6A254o ProductName: Mac OS X ProductVersion: 10.9.4 BuildVersion: 13E28 Swift version 1.0 (swift-600.0.38.7) Target: x86_64-apple-darwin13.3.0 Notes: A half-open range with negative endpoint reports the expected range: === 3> 0..<(-2) $R2: Range<Int> = 0..<-2 4> 0..<(-1) $R3: Range<Int> = 0..<-1 ===
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!