forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoverload_member.swift
194 lines (156 loc) · 4.5 KB
/
overload_member.swift
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
// RUN: %target-parse-verify-swift
struct X { }
struct Y { }
struct Z { }
class A {
func f(x x: X) -> X { }
func f(y y: Y) -> Y { }
func g(z z: Z) -> X { } // expected-note 2{{found this candidate}}
func g(z z: Z) -> Y { } // expected-note 2{{found this candidate}}
class func sf(x x: X) -> X { }
class func sf(y y: Y) -> Y { }
class func sg(z z: Z) -> X { } // expected-note 2{{found this candidate}}
class func sg(z z: Z) -> Y { } // expected-note 2{{found this candidate}}
func mixed(x x: X) -> X { }
class func mixed(y y: Y) -> Y { }
func mixed2(z z: Z) -> X { }
class func mixed2(z 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, inout x: X, inout y: 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, inout x: X, inout y: 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{{incorrect argument label in call (have 'y:', expected 'x:')}}
A.mixed(x) // expected-error{{cannot convert value of type 'X' to expected argument type 'Y'}}
var x2 = A.mixed(a)(x: x)
x2 = x
var y2 = A.mixed(y: y)
y2 = y
}
func test_mixed_overload_coerce(a: A, inout x: 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{{cannot convert value of type '(x: X) -> X' to specified type '(Y) -> Y'}}
var _ : (A) -> (X) -> X = A.mixed;
}
extension A {
func test_method_overload(x 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(inout x x: X, inout y: 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(inout x x: 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{{cannot convert value of type '(x: X) -> X' to specified type '(Y) -> Y'}}
var _ : (Y) -> Y = mixed; // expected-error{{cannot convert value of type '(x: X) -> X' to specified type '(Y) -> Y'}}
var _ : (A) -> (X) -> X = A.mixed;
}
class func test_method_overload_static(x 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(inout x x: X, inout y: 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: A, x: X, y: Y) {
mixed(x) // expected-error{{cannot convert value of type 'X' to expected argument type 'Y'}}
var x2 = mixed(a)(x: x)
x2 = x
var y2 = mixed(y: y)
y2 = y
}
class func test_mixed_overload_coerce_static(y 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'}}
var b : Y = clams // expected-error{{member 'clams' cannot be used on type 'WeirdIvarLookupBehavior'}}
}
}