Swift: Calling a method with a parameter whose type is defined by a generic inheritance constraint crashes the compiler with a segmentation fault

Originator:alex
Number:rdar://22870303 Date Originated:26-Sep-2015 08:32 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xocde 7 & 7.1 beta 2
Classification:Crash Reproducible:Always
 
Summary:
When a method takes a parameter of generic type S that has a constraint to inherit from a generic class (e.g. "S: GenericClass<U>") and this parameter is used as a method argument, the swift compiler crashes with Segmentation fault: 11

Steps to Reproduce:
Open the sample project and try to compile it

Expected Results:
The code should compile fine

Actual Results:
The swift compiler crashes with Segmentation fault: 11

Version:
Xcode 7.0 (7A218) and 7.1 beta (7B75)

Notes:
Adding an explicit cast of newOperation to ResultOperation<S> (i.e. replacing the method argument "newOperation" in main.swift:22 by "newOperation as! ResultOperation<S>") circumvents the problem. 

I believe the root cause is the same as in rdar://22870249 which takes the same configuration and has the same workarounds but only results in a compiler error and not a segmentation fault

Configuration:
This issue does not occur if ResultOperation is not a generic class

Attachments:
'SampleProject.zip' was successfully uploaded.

This contains the following file:

class ResultOperation<ResultType> {
}

class OperationChain<LastReturnType> {
	func chain<T, O: ResultOperation<T>>(newOperation: O) -> OperationChain<T>? {
		return nil
	}
}

func chain<L, S, U: ResultOperation<S>>(operationChain: OperationChain<L>, newOperation: U) -> OperationChain<S>? {
	let x: OperationChain<L>? = nil
	let a = x?.chain(newOperation)
	return nil
}

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!