mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
A protocol can constrain an associated type to Self:
protocol P {
associatedtype A : Q where A.B == Self
}
protocol Q {
associatedtype B
}
And a class might conform to this protocol:
class C : P {
typealias A = D
}
class D : Q {
typealias B = C
}
The generic signature <Self where Self : P, Self : C> is built during
conformance checking. Since Self : C, we must have that Self.A == D;
since D.B == C, the requierement 'A.B == Self' in protocol P implies
that 'Self == C'. So the correct minimized signature here is
<Self where Self == C>.
This wasn't handled properly before, because of assumptions in
removeSelfDerived() and a couple of other places.
Fixes rdar://71677712, rdar://76155506, https://bugs.swift.org/browse/SR-10033,
https://bugs.swift.org/browse/SR-13884.
21 lines
317 B
Swift
21 lines
317 B
Swift
// RUN: %target-swift-frontend -emit-ir -verify %s
|
|
|
|
protocol P1 {
|
|
associatedtype A2 : P2 where A2.A1 == Self
|
|
}
|
|
|
|
protocol P2 {
|
|
associatedtype A1 : P1 where A1.A2 == Self
|
|
var property: Int { get }
|
|
}
|
|
|
|
extension P2 {
|
|
var property: Int { return 0 }
|
|
}
|
|
|
|
class C1 : P1 {
|
|
class A2 : P2 {
|
|
typealias A1 = C1
|
|
}
|
|
}
|