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

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to