From Protocol Types Cannot Conform to Protocols document:
The word "Currently" is encouraging. Are there plans to make amendments here? For example have a notion of restricted protocol that can't have initialisers / static members, which would allow the existential of type P conform to P.
bikeshedding:
Edited:
Wrong example
restricted protocol Animal {
init() // 🛑 Error, can't have initializers in restricted protocols
static func foo() // 🛑 Error, can't static members in restricted protocols
func makeNoise()
}
func declareAnimalSpecies<T: Animal>(_ animal: T) {
animal.makeNoise()
}
var animal: Animal = Dog()
declareAnimalSpecies(animal) // ✅
Corrected example:
restricted protocol CanMakeNoise {
func makeNoise()
}
struct Dog: CanMakeNoise {
func makeNoise() { print("Woof") }
}
func declareAnimalSpecies<T: CanMakeNoise>(_ animal: T) {
animal.makeNoise()
}
extension Array: CanMakeNoise where Element: CanMakeNoise {
func makeNoise() {
forEach { element in
element.makeNoise()
}
}
}
var animal: CanMakeNoise = Dog()
declareAnimalSpecies([animal]) // ✅
// currently gives error
Or perhaps a version of "frozen" attribute, which if apply to a protocol that doesn't have inits/statics would make it "restricted".