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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
|
// RUN: %target-typecheck-verify-swift
struct X { }
struct Y { }
struct Z { }
class A {
func f(x: X) -> X { }
func f(y: Y) -> Y { }
func g(z: Z) -> X { } // expected-note 2{{found this candidate}}
func g(z: Z) -> Y { } // expected-note 2{{found this candidate}}
class func sf(x: X) -> X { }
class func sf(y: Y) -> Y { }
class func sg(z: Z) -> X { } // expected-note 2{{found this candidate}}
class func sg(z: Z) -> Y { } // expected-note 2{{found this candidate}}
func mixed(x: X) -> X { }
class func mixed(y: Y) -> Y { }
func mixed2(z: Z) -> X { }
class func mixed2(z: Z) -> Y { }
}
func test_method_overload(_ a: A, x: X, y: Y) {
var x1 = a.f(x: x)
x1 = x
_ = x1
var y1 = a.f(y: y)
y1 = y
_ = y1
}
func test_method_overload_coerce(_ a: A, x: inout X, y: inout Y, z: Z) {
var fail = a.g(z: z) // expected-error{{ambiguous use of 'g(z:)'}}
x = a.g(z: z)
y = a.g(z: z)
}
func test_method_value_coerce(_ a: A) {
var _ : (X) -> X = a.f
var _ : (A) -> (X) -> X = A.f
}
func test_static_method_overload(_ a: A, x: X, y: Y) {
var x1 = A.sf(x: x)
x1 = x
_ = x1
var y1 = A.sf(y: y)
y1 = y
_ = y1
}
func test_static_method_overload_coerce(_ a: A, x: inout X, y: inout Y, z: Z) {
var fail = A.sg(z: z) // expected-error{{ambiguous use of 'sg(z:)'}}
x = A.sg(z: z)
y = A.sg(z: z)
}
func test_static_method_value_coerce(_ a: A) {
var _ : (X) -> X = A.sf
var _ : (Y) -> Y = A.sf
}
func test_mixed_overload(_ a: A, x: X, y: Y) {
var x1 = a.mixed(x: x)
x1 = x
var y1 = a.mixed(y: y) // expected-error {{static member 'mixed' cannot be used on instance of type 'A'}} {{12-13=A}}
A.mixed(x) // expected-error{{cannot convert value of type 'X' to expected argument type 'A'}}
var x2 = A.mixed(a)(x: x)
x2 = x
var y2 = A.mixed(y: y)
y2 = y
}
func test_mixed_overload_coerce(_ a: A, x: inout X, y: Y, z: Z) {
_ = a.mixed2(z: z)
var y1 = A.mixed2(z: z)
y1 = y
_ = y1
x = a.mixed2(z: z)
}
func test_mixed_method_value_coerce(_ a: A) {
var _ : (X) -> X = a.mixed
var _ : (Y) -> Y = A.mixed
var _ : (Y) -> Y = a.mixed; // expected-error {{static member 'mixed' cannot be used on instance of type 'A'}} {{22-23=A}}
var _ : (A) -> (X) -> X = A.mixed
}
extension A {
func test_method_overload(x: X, y: Y) {
var x1 = self.f(x: x)
x1 = x
_ = x1
var x2 = f(x: x)
x2 = x
_ = x2
var y1 = self.f(y: y)
y1 = y
_ = y1
var y2 = f(y: y)
y2 = y
_ = y2
}
func test_method_overload_coerce(x: inout X, y: inout Y, z: Z) {
var fail = g(z: z) // expected-error{{ambiguous use of 'g(z:)'}}
x = g(z: z)
y = g(z: z)
}
func test_method_value_coerce() {
var _ : (X) -> X = f
var _ : (A) -> (X) -> X = A.f
var _ : (A) -> (X) -> X = A.f
}
func test_mixed_overload_coerce(x: inout X, y: Y, z: Z) {
_ = mixed2(z: z)
x = mixed2(z: z)
}
func test_mixed_method_value_coerce() {
var _ : (X) -> X = mixed
var _ : (Y) -> Y = mixed; // expected-error {{static member 'mixed' cannot be used on instance of type 'A'}} {{24-24=A.}}
var _ : (Y) -> Y = mixed; // expected-error {{static member 'mixed' cannot be used on instance of type 'A'}} {{24-24=A.}}
var _ : (A) -> (X) -> X = A.mixed
}
class func test_method_overload_static(x: X, y: Y, z: Z) {
var x1 = sf(x: x)
x1 = x
_ = x1
var y1 = sf(y: y)
y1 = y
_ = y1
}
class func test_method_overload_coerce_static(x: inout X, y: inout Y, z: Z) {
var fail = sg(z: z) // expected-error{{ambiguous use of 'sg(z:)'}}
x = sg(z: z)
y = sg(z: z)
}
class func test_method_value_coerce_static() {
var _ : (X) -> X = sf
var _ : (Y) -> Y = sf
}
class func test_mixed_overload_static(a: A, x: X, y: Y) {
mixed(x) // expected-error{{cannot convert value of type 'X' to expected argument type 'A'}}
var x2 = mixed(a)(x: x)
x2 = x
var y2 = mixed(y: y)
y2 = y
}
class func test_mixed_overload_coerce_static(y: Y, z: Z) {
var y1 = mixed2(z: z)
y1 = y
_ = y1
}
class func test_mixed_method_value_coerce_static() {
var _ : (Y) -> Y = mixed
var _ : (A) -> (X) -> X = mixed
}
}
var clams : X
struct WeirdIvarLookupBehavior {
var clams : Y
func f() {
var _ : Y = clams
}
static func static_f() {
// FIXME: These diagnostics still suck.
var a : X = clams // expected-error{{member 'clams' cannot be used on type 'WeirdIvarLookupBehavior'}}
// expected-error@-1 {{cannot convert value of type 'Y' to specified type 'X'}}
var b : Y = clams // expected-error{{member 'clams' cannot be used on type 'WeirdIvarLookupBehavior'}}
}
}
|