File: interdependent_protocol_conformance_example_5.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (75 lines) | stat: -rw-r--r-- 3,114 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// RUN: %target-typecheck-verify-swift
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -disable-requirement-machine-reuse 2>&1 | %FileCheck %s

// CHECK-LABEL: .NonEmptyProtocol@
// 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>

public protocol NonEmptyProtocol: Collection
  where Element == C.Element,
        Index == C.Index {
  associatedtype C: Collection
}

// CHECK-LABEL: .MultiPoint@
// 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>

public protocol MultiPoint {
  associatedtype C: CoordinateSystem
  associatedtype P: Point where Self.P == Self.C.P

  associatedtype X: NonEmptyProtocol
    where X.C: NonEmptyProtocol,
          X.Element == Self.P 
}

// CHECK-LABEL: .CoordinateSystem@
// 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>

public protocol CoordinateSystem {
  associatedtype P: Point where Self.P.C == Self
  associatedtype S: Size where Self.S.C == Self
  associatedtype L: Line where Self.L.C == Self
  associatedtype B: BoundingBox where Self.B.C == Self
}

// CHECK-LABEL: .Line@
// CHECK-NEXT: Requirement signature: <Self where Self : MultiPoint, Self.[MultiPoint]C == Self.[MultiPoint]P.[Point]C>

public protocol Line: MultiPoint {}

// CHECK-LABEL: .Size@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.[Size]C.[CoordinateSystem]S, Self.[Size]C : CoordinateSystem>

public protocol Size {
  associatedtype C: CoordinateSystem where Self.C.S == Self
}

// CHECK-LABEL: .BoundingBox@
// CHECK-NEXT: Requirement signature: <Self where Self.[BoundingBox]C : CoordinateSystem>

public protocol BoundingBox {
  associatedtype C: CoordinateSystem
  typealias P = Self.C.P
  typealias S = Self.C.S
}

// CHECK-LABEL: .Point@
// CHECK-NEXT: Requirement signature: <Self where Self == Self.[Point]C.[CoordinateSystem]P, Self.[Point]C : CoordinateSystem>

public protocol Point { 
  associatedtype C: CoordinateSystem where Self.C.P == Self
}

func sameType<T>(_: T, _: T) {}

func conformsToPoint<T : Point>(_: T.Type) {}

func testMultiPoint<T : MultiPoint>(_: T) {
  sameType(T.C.P.self, T.X.Element.self)
  conformsToPoint(T.P.self)
}

func testCoordinateSystem<T : CoordinateSystem>(_: T) {
  sameType(T.P.C.self, T.self)
}