Swift: Using elements of Sliceable constrained to be recursive crashes the compiler

Originator:rix.rob
Number:rdar://19335891 Date Originated:23-Dec-2014 10:10 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.1.1 (6A2008a)
Classification:Other Bug Reproducible:Always
 
Summary:
The compiler crashes when I destructure & use the elements of a Sliceable constrained to be recursive.


Steps to Reproduce:
1. Write this:

func uncons<S: Sliceable>(sliceable: S) -> (S.Generator.Element, S.SubSlice)? {
	return first(sliceable).map { ($0, dropFirst(sliceable)) }
}

struct Pattern<T, U> {
	let f: T -> U?
}

func cond<T, U, S: Sliceable where S.SubSlice == S, S.Generator.Element == Pattern<T, U>>(x: T, patterns: S) -> U? {
	return uncons(patterns).map { pattern, rest in pattern.f(x) } ?? nil
}


Expected Results:
I expected it to run.


Actual Results:
The compiler crashes.


Regression:
It doesn’t crash if you remove the recursive slice constraint (S.SubSlice == S).

I couldn’t make an iterative version of this due to spurious errors, radar to follow.


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!