protocol P { init(name: String) func a() -> Self } struct S : P { init(name: String) {} func a() -> S { fatalError() } } func takeExistentialArg(_ p: P) {}
protocol P { init(name: String) func a() -> Self } protocol Q { func takeSelf(_ self_: Self) } func takeExistentialArgP(_ p: P) {} // Protocol 'Q' can only be used as a generic constraint because it has Self or associated type requirements func takeExistentialArgQ(_ q: Q) {}
protocol P { init(name: String) func a() -> Self } protocol Q { func takeSelf(_ self_: Self) } extension P { func takeSelf(_ self_: Self) { } } func takeExistentialArgP(_ p: P) {}
extension P { func transfer(_ self_: Self) -> Self { return self_ } } func takeExistentialArgP(_ p: P) { // Member 'transfer' cannot be used on value of protocol type 'P'; use a generic constraint instead let a = p.transfer(p) }
func foo<T: P>(_: T) extension P { func _forwardToFoo() { foo(self) } } func callFooOnEach(_ ps: [P]) { for p in ps { p._forwardToFoo() } }