Swift: Crash 2 of 3 when calling functions returned by functions taking functions and passing functions

Originator:rix.rob
Number:rdar://18548369 Date Originated:04-Oct-2014 06:23 PM
Status:Open Resolved:
Product:Developer Tools Product Version:
Classification:Serious Bug Reproducible:Always
 
Summary:
Trying to narrow down the reduceLeft runtime crashes (and e.g. find a workaround) I instead found a bunch of compiler crashes. This is 2 of 3 so far.

TL;DR: Basically never call functions returned by functions taking functions passing them functions.


Steps to Reproduce:
1. Compile this.

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 })
}


Expected Results:
No crash.


Actual Results:
Crash.


Regression:
Instead of finding ways for this not to crash, all I’ve found is subtly different ways in which it might crash instead.


Notes:
This is apparently what I do with my Saturday nights.

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!