Yes, so for completeness, here's how to conditionally conform MyArrayOfOne
to Foobarable
(leaving Array
and Optional
there to demonstrate -- what turned out to probably be -- the actual bug):
protocol Fooable {
func foo()
}
protocol Barable {
func bar()
}
protocol Foobarable : Fooable, Barable {
}
// Conditionally conforming Array to Foobarable works by just doing this:
extension Array: Foobarable where Element: Foobarable {
func foo() { forEach { $0.foo() } }
func bar() { forEach { $0.bar() } }
}
// Even though it probably shouldn't. The same goes for eg Optional:
extension Optional: Foobarable where Wrapped: Foobarable {
func foo() { self?.foo() }
func bar() { self?.bar() }
}
// But, as discussed above, in order to conditionally conform eg this:
struct MyArrayOfOne<Element> {
let element: Element
}
// You have state each conformance explicitly:
extension MyArrayOfOne: Fooable where Element: Fooable {
func foo() { element.foo() }
}
extension MyArrayOfOne: Barable where Element: Barable {
func bar() { element.bar() }
}
extension MyArrayOfOne: Foobarable where Element: Foobarable {
}
// This compiles with default toolchain of Xcode 9.3 beta 4.