Swift: Interpreter barfs all over the console for a specific (crashing) case
| Originator: | rix.rob | ||
| Number: | rdar://18548409 | Date Originated: | 04-Oct-2014 06:38 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-6.1 (6A1042b) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
When I run a Swift script which triggers a compiler crash, the interpreter barfs binary garbage all over the console.
Steps to Reproduce:
Put this in a script and run it:
#!/usr/bin/env xcrun swift
public struct ReducibleOf<T> {
public init<S : SequenceType where S.Generator.Element == T>(_ sequence: S) {}
public func reduceLeft<Result>(recur: (ReducibleOf, Result, (Result, T) -> Result) -> Result) -> (ReducibleOf, Result, (Result, T) -> Result) -> Result {
return { _, x, _ in x }
}
}
func testReduction() {
let sequence = [1, 2, 3, 4, 5, 6, 7, 8, 9]
let reducible = ReducibleOf(sequence)
var result = 0
var take: (ReducibleOf<Int>, Int, (Int, Int) -> Int) -> Int = { reducible, initial, combine in
result = initial
return initial
}
var x = reducible.reduceLeft(take)(reducible, 0 as Int, { into, each in each })
}
Note that it MUST NOT have a newline at the end of the file to trigger this issue. I.e. the last byte in the file should be the closing }.
Expected Results:
I certainly didn’t expect it to spew garbage everywhere.
Actual Results:
It spewed garbage… everywhere.
Regression:
- doesn’t do it with other scripts whether I have a trailing newline or not
- doesn’t do it with this script if there’s a trailing newline
- doesn’t do it if I redirect output to a file—the file just ends up being empty
- wtf
Notes:
Kind of a cool party trick I guess.
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!