|
| 1 | +// RUN: %target-typecheck-verify-swift -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on |
| 2 | +// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s |
| 3 | +// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-requirement-machine-reuse -requirement-machine-protocol-signatures=on -requirement-machine-inferred-signatures=on 2>&1 | %FileCheck %s |
| 4 | + |
| 5 | +// CHECK-LABEL: .NonEmptyProtocol@ |
| 6 | +// CHECK-NEXT: Requirement signature: <Self where Self : Collection, Self.[NonEmptyProtocol]C : Collection, Self.[Sequence]Element == Self.[NonEmptyProtocol]C.[Sequence]Element, Self.[Collection]Index == Self.[NonEmptyProtocol]C.[Collection]Index> |
| 7 | + |
| 8 | +public protocol NonEmptyProtocol: Collection |
| 9 | + where Element == C.Element, |
| 10 | + Index == C.Index { |
| 11 | + associatedtype C: Collection |
| 12 | +} |
| 13 | + |
| 14 | +// CHECK-LABEL: .MultiPoint@ |
| 15 | +// CHECK-NEXT: Requirement signature: <Self where Self.[MultiPoint]C : CoordinateSystem, Self.[MultiPoint]P == Self.[MultiPoint]C.[CoordinateSystem]P, Self.[MultiPoint]X : NonEmptyProtocol, Self.[MultiPoint]C.[CoordinateSystem]P == Self.[MultiPoint]X.[Sequence]Element, Self.[MultiPoint]X.[NonEmptyProtocol]C : NonEmptyProtocol> |
| 16 | + |
| 17 | +public protocol MultiPoint { |
| 18 | + associatedtype C: CoordinateSystem |
| 19 | + associatedtype P: Point where Self.P == Self.C.P |
| 20 | + // expected-warning@-1 {{redundant conformance constraint 'Self.P' : 'Point'}} |
| 21 | + |
| 22 | + associatedtype X: NonEmptyProtocol |
| 23 | + where X.C: NonEmptyProtocol, |
| 24 | + X.Element == Self.P |
| 25 | +} |
| 26 | + |
| 27 | +// CHECK-LABEL: .CoordinateSystem@ |
| 28 | +// CHECK-NEXT: Requirement signature: <Self where Self == Self.[CoordinateSystem]B.[BoundingBox]C, Self.[CoordinateSystem]B : BoundingBox, Self.[CoordinateSystem]L : Line, Self.[CoordinateSystem]P : Point, Self.[CoordinateSystem]S : Size, Self.[CoordinateSystem]B.[BoundingBox]C == Self.[CoordinateSystem]L.[MultiPoint]C, Self.[CoordinateSystem]L.[MultiPoint]C == Self.[CoordinateSystem]S.[Size]C> |
| 29 | + |
| 30 | +public protocol CoordinateSystem { |
| 31 | + associatedtype P: Point where Self.P.C == Self |
| 32 | + associatedtype S: Size where Self.S.C == Self |
| 33 | + associatedtype L: Line where Self.L.C == Self |
| 34 | + associatedtype B: BoundingBox where Self.B.C == Self |
| 35 | +} |
| 36 | + |
| 37 | +// CHECK-LABEL: .Line@ |
| 38 | +// CHECK-NEXT: Requirement signature: <Self where Self : MultiPoint, Self.[MultiPoint]C == Self.[MultiPoint]P.[Point]C> |
| 39 | + |
| 40 | +public protocol Line: MultiPoint {} |
| 41 | + |
| 42 | +// CHECK-LABEL: .Size@ |
| 43 | +// CHECK-NEXT: Requirement signature: <Self where Self == Self.[Size]C.[CoordinateSystem]S, Self.[Size]C : CoordinateSystem> |
| 44 | + |
| 45 | +public protocol Size { |
| 46 | + associatedtype C: CoordinateSystem where Self.C.S == Self |
| 47 | +} |
| 48 | + |
| 49 | +// CHECK-LABEL: .BoundingBox@ |
| 50 | +// CHECK-NEXT: Requirement signature: <Self where Self.[BoundingBox]C : CoordinateSystem> |
| 51 | + |
| 52 | +public protocol BoundingBox { |
| 53 | + associatedtype C: CoordinateSystem |
| 54 | + typealias P = Self.C.P |
| 55 | + typealias S = Self.C.S |
| 56 | +} |
| 57 | + |
| 58 | +// CHECK-LABEL: .Point@ |
| 59 | +// CHECK-NEXT: Requirement signature: <Self where Self == Self.[Point]C.[CoordinateSystem]P, Self.[Point]C : CoordinateSystem> |
| 60 | + |
| 61 | +public protocol Point { |
| 62 | + associatedtype C: CoordinateSystem where Self.C.P == Self |
| 63 | +} |
| 64 | + |
| 65 | +func sameType<T>(_: T, _: T) {} |
| 66 | + |
| 67 | +func conformsToPoint<T : Point>(_: T.Type) {} |
| 68 | + |
| 69 | +func testMultiPoint<T : MultiPoint>(_: T) { |
| 70 | + sameType(T.C.P.self, T.X.Element.self) |
| 71 | + conformsToPoint(T.P.self) |
| 72 | +} |
| 73 | + |
| 74 | +func testCoordinateSystem<T : CoordinateSystem>(_: T) { |
| 75 | + sameType(T.P.C.self, T.self) |
| 76 | +} |
0 commit comments