Swift: runtime crash in non-optional binary function made with generic composition operator
| Originator: | rix.rob | ||
| Number: | rdar://19116900 | Date Originated: | 02-Dec-2014 02:12 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode 6.1.1 (6A2006) |
| Classification: | Crash/Hang/Data Loss | Reproducible: | Always |
Summary:
I’m composing the first function from Swift‘s stdlib with == over T? using a left-to-right composition operator, >>>. When I call it, it crashes if its second operand is typed as Int but not if it’s typed as Int?, but both compile just fine *and* both work when defined manually.
Steps to Reproduce:
Run this:
infix operator >>> {}
public func >>> <T, U, V, W> (f: T -> U, g: (U, V) -> W) -> (T, V) -> W {
return { g(f($0), $1) }
}
let array = [1, 2, 3]
let manualOptional: ([Int], Int?) -> Bool = { (==)(first($0), $1) }
if manualOptional(array, 1) {
println("manual optional")
}
let manualNonOptional: ([Int], Int) -> Bool = { (==)(first($0), $1) }
if manualNonOptional(array, 1) {
println("manual nonoptional")
}
let composedOptional: ([Int], Int?) -> Bool = (first >>> (==))
if composedOptional(array, 1) {
println("composed optional")
}
let composedNonOptional: ([Int], Int) -> Bool = (first >>> (==))
if composedNonOptional([1, 2, 3], 1) {
println("composed nonoptional")
}
Expected Results:
I expected it to print all four strings.
Actual Results:
It prints the first three, and then crashes.
Regression:
N/A
Notes:
Crash log attached.
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!