[swift-evolution] Pitch: Small fix to where clauses in generics

Charles Srstka cocoadev at charlessoft.com
Fri May 27 11:30:01 CDT 2016


Forgive me if this has already been proposed in one of the generics threads; I did a quick check and didn’t see anything.

Currently, the code below does not compile:

protocol P {}

struct S: P {}

extension SequenceType where Generator.Element: P {
	func foo() {}
}

func F(arr: [P]) {
	arr.foo() // error: using 'P' as a concrete type conforming to protocol 'P' is not supported
}

If one changes the where clause in the extension to say Generator.Element == P instead of : P, the above now works fine, but then the below does not:

protocol P {}

struct S: P {}

extension SequenceType where Generator.Element == P {
	func foo() {}
}

func F(arr: [S]) {
	arr.foo() // error: 'P' is not convertible to 'S'
}

It seems to me that the first example ought to work; if our constraint is that Generator.Element conforms to P, something typed as P itself should probably fit the requirement.

Charles



More information about the swift-evolution mailing list