File: unsatisfiable.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 (82 lines) | stat: -rw-r--r-- 2,602 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// RUN: %target-typecheck-verify-swift -swift-version 4

protocol P {
  associatedtype A
  associatedtype B

  func f<T: P>(_: T) where T.A == Self.A, T.A == Self.B // expected-error{{instance method requirement 'f' cannot add constraint 'Self.A == Self.B' on 'Self'}}
  // expected-note@-1 {{protocol requires function 'f' with type '<T> (T) -> ()'; add a stub for conformance}}
}

extension P {
  func f<T: P>(_: T) where T.A == Self.A, T.A == Self.B { }
  // expected-note@-1 {{candidate would match if 'X' was the same type as 'X.B' (aka 'Int')}}
}

struct X : P { // expected-error {{type 'X' does not conform to protocol 'P'}}
  typealias A = X
  typealias B = Int
}

protocol P2 {
  associatedtype A

  func f<T: P2>(_: T) where T.A == Self.A, T.A: P2 // expected-error{{instance method requirement 'f' cannot add constraint 'Self.A: P2' on 'Self'}}
}

class C { }

protocol P3 {
  associatedtype A

  func f<T: P3>(_: T) where T.A == Self.A, T.A: C // expected-error{{instance method requirement 'f' cannot add constraint 'Self.A: C' on 'Self'}}
  func g<T: P3>(_: T) where T.A: C, T.A == Self.A  // expected-error{{instance method requirement 'g' cannot add constraint 'Self.A: C' on 'Self'}}
}

protocol Base {
  associatedtype Assoc
}

protocol Sub1: Base {
  associatedtype SubAssoc: Assoc
  // expected-error@-1 {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}}
}

// FIXME: This error is incorrect in what it states.
protocol Sub2: Base {
  associatedtype SubAssoc where SubAssoc: Assoc // expected-error {{type 'Self.SubAssoc' constrained to non-protocol, non-class type 'Self.Assoc'}}
}

struct S {}

// FIX-ME: One of these errors is redundant.
protocol P4 {
  associatedtype X : S
  // expected-error@-1 {{type 'Self.X' constrained to non-protocol, non-class type 'S'}}
}

protocol P5 {
  associatedtype Y where Y : S // expected-error {{type 'Self.Y' constrained to non-protocol, non-class type 'S'}}
}

protocol P6 {
  associatedtype T
  associatedtype U

  func foo() where T == U
  // expected-error@-1 {{instance method requirement 'foo()' cannot add constraint 'Self.T == Self.U' on 'Self'}}
  // expected-note@-2 {{protocol requires function 'foo()' with type '() -> ()'; add a stub for conformance}}
}

struct S2 : P6 {
  // expected-error@-1 {{type 'S2' does not conform to protocol 'P6'}}
  typealias T = Int
  typealias U = String

  func foo() {}
  // expected-note@-1 {{candidate has non-matching type '() -> ()'}}

  // FIXME: This error is bogus and should be omitted on account of the protocol requirement itself
  // being invalid.
}