Swift map with Void function crashes at runtime
| Originator: | brent | ||
| Number: | rdar://17316088 | Date Originated: | 14-Jun-2014 01:19 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode6-Beta (6A215l) |
| Classification: | Crash/Hang/Data Loss | Reproducible: | Always |
Summary:
If map is used with a function returning Void, Swift crashes at runtime.
Steps to Reproduce:
1. Run code like this, either compiled or in the REPL:
func sideEffectsFunc(arg: String) { /* do something with arg */ }
["a", "b"].map(sideEffectsFunc)
Expected Results:
Swift invokes sideEffectsFunc and returns an array of Void, which I’m free to ignore.
Actual Results:
The resulting program crashes while trying to run Array.map.
In compiled code (32-bit iPhone Simulator), the exact error is EXC_BAD_INSTRUCTION (code=EXC_i386_INVOP, subcode=0x0) in Swift.HeapBuffer._capacity at 0x137b26.
Notes:
The actual code in my app is:
rowViews.map(addSubview)
Which is the second-coolest thing I’ve written in this app so far. (The coolest is the use of reduce() to connect rows and columns of views with repeating patterns of layout constraints.) I hope this idiom, or something very similar, becomes officially supported—it’d be a shame to write a whole for loop when this elegant functional construct is available instead.
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!