File: parameter-pack-same-element-requirements.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 (59 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download
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
// RUN: %target-swift-frontend -typecheck %s -debug-generic-signatures -enable-experimental-feature SameElementRequirements -disable-availability-checking 2>&1 | %FileCheck %s -dump-input=fail

// REQUIRES: swift_feature_SameElementRequirements

protocol P {
  associatedtype A

  func f(_ self: Self) -> Self
}

//////
///
/// Same-element requirements.
///
//////

// FIXME: Implement concrete same-type requirements.
//func sameElementConcrete<each T>(
//  _: repeat each T
//) where repeat each T == Int {}

// CHECK-LABEL: sameElementGeneric
// CHECK-NEXT: Generic signature: <each T, U where repeat each T == U>
func sameElementGeneric<each T, U>(
  _: repeat each T
) where repeat each T == U {}

// FIXME: Implement concrete same-element requirements.
//func dependentSameElementConcrete<each C: Collection>(
//  _: repeat each C
//) where repeat (each C).Element == Int {}

// CHECK-LABEL: dependentSameElementGeneric
// CHECK-NEXT: Generic signature: <each C, Element where repeat each C : Collection, repeat Element == (each C).[Sequence]Element>
func dependentSameElementGeneric<each C: Collection, Element>(
  _: repeat each C
) where repeat (each C).Element == Element {}

// FIXME: Either 'repeat each T: P' or 'U: P' should be redundant.
// CHECK-LABEL: sameElementRedundantConformance
// CHECK-NEXT: Generic signature: <each T, U where repeat each T : P, repeat each T == U, U : P>
func sameElementRedundantConformance<each T, U>(
  t: repeat each T,
  u: U
) where repeat each T: P,
        repeat each T == U {
  let _ = (repeat (each t).f(u))
}

// CHECK-LABEL: forEachEach
// CHECK-NEXT: Generic signature: <each C, U where repeat each C : Collection, repeat U == (each C).[Sequence]Element>
func forEachEach<each C, U>(
  c: repeat each C,
  function: (U) -> Void
) where repeat each C: Collection,
        repeat (each C).Element == U {
  repeat (each c).forEach(function)
}