Swift: Trying to `swap` the same location is a fatal error
| Originator: | natecook | ||
| Number: | rdar://22440946 | Date Originated: | 26-Aug-2015 01:30 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-beta (7A192o) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary: In the latest Swift beta, when calling `swap()` with the same value as both parameters, Swift throws a run-time error. This is a regression from previous versions of Swift, where such a call executed safely. Steps to Reproduce: 1) Create a new playground (attached), and add the following code: var a = [1, 2, 3, 4, 5] swap(&a[0], &a[1]) swap(&a[0], &a[0]) print(a) Expected Results: The console should show [2, 1, 3, 4, 5] Actual Results: The playground shows a runtime error on the third line and the console reads “fatal error: swapping a location with itself is not supported” Regression: This has worked in all previous versions of Swift.
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!