File: inverse_scoping.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 (63 lines) | stat: -rw-r--r-- 2,937 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
60
61
62
63
// RUN: %target-typecheck-verify-swift  -enable-experimental-feature SuppressedAssociatedTypes

// REQUIRES: swift_feature_SuppressedAssociatedTypes



protocol NoCopyReq: ~Copyable {}

protocol P {
  func f() where Self: ~Copyable // expected-error {{cannot suppress '~Copyable' on generic parameter 'Self' defined in outer scope}}

  func g<T>(_: T) where Self: ~Copyable // expected-error {{cannot suppress '~Copyable' on generic parameter 'Self' defined in outer scope}}

  associatedtype AT where Self: ~Copyable // expected-error {{constraint with subject type of 'Self' is not supported; consider adding requirement to protocol inheritance clause instead}}

  // expected-error@+1 {{cannot suppress '~Copyable' on generic parameter 'Self.Alice' defined in outer scope}}
  associatedtype Bob where Alice: NoCopyReq & ~Copyable
  associatedtype Alice where Bob: ~Copyable
  // expected-error@-1 {{cannot suppress '~Copyable' on generic parameter 'Self.Bob' defined in outer scope}}
}

protocol U {}

extension U where Self: ~Copyable {}
// expected-error@-1 {{'Self' required to be 'Copyable' but is marked with '~Copyable'}}

extension P where Self: ~Copyable {
  func g() where Self: ~Copyable, // expected-error {{cannot suppress '~Copyable' on generic parameter 'Self' defined in outer scope}}
                                  // FIXME: why no similar 2nd error as Escapable here on Self?

                 Self: ~Escapable {}  // expected-error {{cannot suppress '~Escapable' on generic parameter 'Self' defined in outer scope}}
                                      // expected-error@-1 {{'Self' required to be 'Escapable' but is marked with '~Escapable'}}

  typealias Me = Self where Self: ~Copyable // expected-error {{cannot suppress '~Copyable' on generic parameter 'Self' defined in outer scope}}

  typealias MeAndU = Self where Self: U
}

struct S<T> {

  // expected-note@+2 3{{add}}
  // expected-error@+1 {{parameter of noncopyable type 'U' must specify ownership}}
  func fn<U>(_ u: U)
    where T: ~Copyable, // expected-error {{cannot suppress '~Copyable' on generic parameter 'T' defined in outer scope}}
                        // expected-error@-1 {{'T' required to be 'Copyable' but is marked with '~Copyable'}}
          U: ~Copyable
          {}

  func onlyCopyable() where T: Copyable {}

    func fn<U>(_ u: U)
      where T: ~Escapable, // expected-error {{cannot suppress '~Escapable' on generic parameter 'T' defined in outer scope}}
                           // expected-error@-1 {{'T' required to be 'Escapable' but is marked with '~Escapable'}}
            U: ~Escapable
            {}
}

extension S where T: NoCopyReq & ~Copyable {}
// expected-error@-1 {{'T' required to be 'Copyable' but is marked with '~Copyable'}}

struct ExtraInverse<T: ~Copyable> {
  func check() where T: ~Copyable {} // expected-error {{cannot suppress '~Copyable' on generic parameter 'T' defined in outer scope}}
}