File: rdar39931339.swift

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (53 lines) | stat: -rw-r--r-- 1,693 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
// RUN: %target-typecheck-verify-swift
// RUN: not %target-swift-frontend -typecheck %s -debug-generic-signatures 2>&1 | %FileCheck %s

protocol P {}

struct S<T> {}

class C : P {}

extension S where T : P { // expected-note {{where 'T' = 'T'}}
  typealias A = Int
  typealias B<U> = S<U>
}

extension S where T == Float { // expected-note {{requirement specified as 'T' == 'Float' [with T = Int]}}
  typealias C = Int
}

class A<T, U> {}

// CHECK-LABEL: ExtensionDecl line={{.*}} base=A
// CHECK-NEXT: Generic signature: <T, U where T == [U], U : P>
extension A where T == [U], U: P {
  typealias S1 = Int
}

// CHECK-LABEL: ExtensionDecl line={{.*}} base=A
// CHECK-NEXT: Generic signature: <T, U where T == [Int], U == Int>
extension A where T == [U], U == Int {
// expected-note@-1 {{requirement specified as 'T' == '[Int]' [with T = [String]]}}
  typealias S2 = Int
}

class B<U> : A<[U], U> {}

_ = B<C>.S1()          // Ok
_ = B<Int>.S2()        // Ok
_ = B<Float>.S1()      // expected-error {{type 'Float' does not conform to protocol 'P'}}
_ = B<String>.S2()
// expected-error@-1 {{'A<T, U>.S2' (aka 'Int') requires the types '[String]' and '[Int]' be equivalent}}

_ = S<C>.A()           // Ok
_ = S<Int>.A()         // expected-error {{type 'Int' does not conform to protocol 'P'}}
_ = S<String>.B<Int>() // expected-error {{type 'String' does not conform to protocol 'P'}}
_ = S<Int>.C()         // expected-error {{'S<T>.C' (aka 'Int') requires the types 'Int' and 'Float' be equivalent}}

func foo<T>(_ s: S<T>.Type) {
  _ = s.A() // expected-error {{referencing type alias 'A' on 'S' requires that 'T' conform to 'P'}}
}

func bar<T: P>(_ s: S<T>.Type) {
  _ = s.A() // Ok
}