swift-protocols

Protocol doesn't conform to itself?

删除回忆录丶 提交于 2019-11-25 21:39:07
问题 Why doesn\'t this Swift code compile? protocol P { } struct S: P { } let arr:[P] = [ S() ] extension Array where Element : P { func test<T>() -> [T] { return [] } } let result : [S] = arr.test() The compiler says: \"Type P does not conform to protocol P \" (or, in later versions of Swift, \"Using \'P\' as a concrete type conforming to protocol \'P\' is not supported.\"). Why not? This feels like a hole in the language, somehow. I realize that the problem stems from declaring the array arr as