Swift: Referencing a local function within a closure receiving a value unboxed from its parameter crashes the compiler

Originator:rix.rob
Number:rdar://19153007 Date Originated:04-Dec-2014 11:42 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.1.1 (6A2006)
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
This one is pretty specific.


Steps to Reproduce:
1. Compile this, IF YOU DARE:
func f<T>() {
	func g(y: T) {
		let h: T -> T? = { _ in nil }
		h(y).map { _ in
			g
		}
	}
}


Expected Results:
I expected it to compile or at least to error.


Actual Results:
Crash crash crashity crash crash crash.


Regression:
It does NOT crash if:

- h receives x instead of y
- h is defined outside of g
- the innermost closure doesn’t reference g

If you change the type parameter to be non-generic e.g. Int, it still crashes, but then it’s just boring old rdar://19152922


Notes:
N/A

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!