Given these types:
protocol AProtocol {
associatedtype B: BProtocol where B.A == Self
}
protocol BProtocol {
associatedtype A: AProtocol
}
protocol CProtocol {
associatedtype A: AProtocol
}
protocol DProtocol {
associatedtype A: AProtocol
func foo<C: CProtocol>(c: C) where C.A == A
}
the compiler complains with the error message:
Instance method requirement 'foo(c:)' cannot add constraint 'Self.A.B == Self.A.B.A.B' on 'Self'
which I think is not correct because the associated type B
of AProtocol
is constrained with where B.A == Self
.
This should imply B.A.B == Self.B
and therefore B.A.B.A == Self.B.A == Self
.
Is this correct?
I currently use a "workaround" which adds an additional constraint to the associated type B
of AProtocol
where B.A.B == B
:
protocol AProtocol {
associatedtype B: BProtocol where B.A == Self, B.A.B == B
}
protocol BProtocol {
associatedtype A: AProtocol
}
protocol CProtocol {
associatedtype A: AProtocol
}
protocol DProtocol {
associatedtype A: AProtocol
func foo<C: CProtocol>(c: C) where C.A == A
}
With the addition constraint, this compiles just fine. I'm now curious if this addition requirement is really needed or should be inferred from the first constraint where B.A == Self
.
Tested with Swift 5.5.2 (Xcode 13.2.1) and Swift 5.6 (Xcode 13.3 Beta 3)
Fails to compile with Swift 5.7 (Trunk Development (main) February 25, 2022). Reported as SR-15920 with an even more reduced example. Maybe related to the new generic signature minimization algorithm. cc: @Slava_Pestov)