|
1 |
| -// RUN: %target-swift-emit-silgen %s -verify | %FileCheck %s |
| 1 | +// RUN: %target-swift-emit-silgen %s -verify -swift-version 5 | %FileCheck %s |
2 | 2 |
|
3 | 3 | protocol P {
|
4 | 4 | var p: P { get set }
|
@@ -155,3 +155,116 @@ func testDerived(b: B) {
|
155 | 155 | f0(f1(b))
|
156 | 156 | // CHECK: end sil function '$S7ranking11testDerived1byAA1BC_tF'
|
157 | 157 | }
|
| 158 | + |
| 159 | +protocol X { |
| 160 | + var foo: Int { get } |
| 161 | + var bar: Int { get } |
| 162 | + func baz() -> Int |
| 163 | + subscript(foo: String) -> Int { get } |
| 164 | +} |
| 165 | + |
| 166 | +class Y { |
| 167 | + var foo: Int = 0 |
| 168 | + func baz() -> Int { return foo } |
| 169 | + subscript(foo: String) -> Int { return 0 } |
| 170 | +} |
| 171 | +extension Y { |
| 172 | + var bar: Int { return foo } |
| 173 | +} |
| 174 | + |
| 175 | +protocol Z : Y { |
| 176 | + var foo: Int { get } |
| 177 | + var bar: Int { get } |
| 178 | + func baz() -> Int |
| 179 | + subscript(foo: String) -> Int { get } |
| 180 | +} |
| 181 | + |
| 182 | +class GenericClass<T> { |
| 183 | + var foo: T |
| 184 | + init(_ foo: T) { self.foo = foo } |
| 185 | + func baz() -> T { return foo } |
| 186 | +} |
| 187 | +extension GenericClass { |
| 188 | + var bar: T { return foo } |
| 189 | + subscript(foo: String) -> Int { return 0 } |
| 190 | +} |
| 191 | + |
| 192 | +// Make sure we favour the class implementation over the protocol requirement. |
| 193 | + |
| 194 | +// CHECK-LABEL: sil hidden @$S7ranking32testGenericPropertyProtocolClassyyxAA1YCRbzAA1XRzlF |
| 195 | +func testGenericPropertyProtocolClass<T : X & Y>(_ t: T) { |
| 196 | + _ = t.foo // CHECK: class_method {{%.*}} : $Y, #Y.foo!getter.1 |
| 197 | + _ = t.bar // CHECK: function_ref @$S7ranking1YC3barSivg |
| 198 | + _ = t.baz() // CHECK: class_method {{%.*}} : $Y, #Y.baz |
| 199 | + _ = t[""] // CHECK: class_method {{%.*}} : $Y, #Y.subscript!getter.1 |
| 200 | +} |
| 201 | + |
| 202 | +// CHECK-LABEL: sil hidden @$S7ranking36testExistentialPropertyProtocolClassyyAA1X_AA1YCXcF |
| 203 | +func testExistentialPropertyProtocolClass(_ t: X & Y) { |
| 204 | + _ = t.foo // CHECK: class_method {{%.*}} : $Y, #Y.foo!getter.1 |
| 205 | + _ = t.bar // CHECK: function_ref @$S7ranking1YC3barSivg |
| 206 | + _ = t.baz() // CHECK: class_method {{%.*}} : $Y, #Y.baz |
| 207 | + _ = t[""] // CHECK: class_method {{%.*}} : $Y, #Y.subscript!getter.1 |
| 208 | +} |
| 209 | + |
| 210 | +// CHECK-LABEL: sil hidden @$S7ranking46testGenericPropertySubclassConstrainedProtocolyyxAA1ZRzlF |
| 211 | +func testGenericPropertySubclassConstrainedProtocol<T : Z>(_ t: T) { |
| 212 | + _ = t.foo // CHECK: class_method {{%.*}} : $Y, #Y.foo!getter.1 |
| 213 | + _ = t.bar // CHECK: function_ref @$S7ranking1YC3barSivg |
| 214 | + _ = t.baz() // CHECK: class_method {{%.*}} : $Y, #Y.baz |
| 215 | + _ = t[""] // CHECK: class_method {{%.*}} : $Y, #Y.subscript!getter.1 |
| 216 | +} |
| 217 | + |
| 218 | +// CHECK-LABEL: sil hidden @$S7ranking50testExistentialPropertySubclassConstrainedProtocolyyAA1Z_pF |
| 219 | +func testExistentialPropertySubclassConstrainedProtocol(_ t: Z) { |
| 220 | + _ = t.foo // CHECK: class_method {{%.*}} : $Y, #Y.foo!getter.1 |
| 221 | + _ = t.bar // CHECK: function_ref @$S7ranking1YC3barSivg |
| 222 | + _ = t.baz() // CHECK: class_method {{%.*}} : $Y, #Y.baz |
| 223 | + _ = t[""] // CHECK: class_method {{%.*}} : $Y, #Y.subscript!getter.1 |
| 224 | +} |
| 225 | + |
| 226 | +// CHECK-LABEL: sil hidden @$S7ranking43testExistentialPropertyProtocolGenericClassyyAA1X_AA0fG0CySiGXcF |
| 227 | +func testExistentialPropertyProtocolGenericClass(_ t: GenericClass<Int> & X) { |
| 228 | + _ = t.foo // CHECK: class_method {{%.*}} : $GenericClass<Int>, #GenericClass.foo!getter.1 |
| 229 | + _ = t.bar // CHECK: function_ref @$S7ranking12GenericClassC3barxvg |
| 230 | + _ = t.baz() // CHECK: class_method {{%.*}} : $GenericClass<Int>, #GenericClass.baz |
| 231 | + _ = t[""] // CHECK: function_ref @$S7ranking12GenericClassCySiSScig |
| 232 | +} |
| 233 | + |
| 234 | +// CHECK-LABEL: sil hidden @$S7ranking43testExistentialPropertyProtocolGenericClassyyAA1X_AA0fG0CySSGXcF |
| 235 | +func testExistentialPropertyProtocolGenericClass(_ t: GenericClass<String> & X) { |
| 236 | + _ = t.foo // CHECK: class_method {{%.*}} : $GenericClass<String>, #GenericClass.foo!getter.1 |
| 237 | + _ = t.bar // CHECK: function_ref @$S7ranking12GenericClassC3barxvg |
| 238 | + _ = t.baz() // CHECK: class_method {{%.*}} : $GenericClass<String>, #GenericClass.baz |
| 239 | + _ = t[""] // CHECK: function_ref @$S7ranking12GenericClassCySiSScig |
| 240 | +} |
| 241 | + |
| 242 | +extension X where Self : Y { |
| 243 | + // CHECK-LABEL: sil hidden @$S7ranking1XPA2A1YCRbzrlE32testGenericPropertyProtocolClassyyxF |
| 244 | + func testGenericPropertyProtocolClass(_ x: Self) { |
| 245 | + _ = self.foo // CHECK: class_method {{%.*}} : $Y, #Y.foo!getter.1 |
| 246 | + _ = self.bar // CHECK: function_ref @$S7ranking1YC3barSivg |
| 247 | + _ = self.baz() // CHECK: class_method {{%.*}} : $Y, #Y.baz |
| 248 | + _ = self[""] // CHECK: class_method {{%.*}} : $Y, #Y.subscript!getter.1 |
| 249 | + } |
| 250 | +} |
| 251 | + |
| 252 | +extension X where Self : GenericClass<Int> { |
| 253 | + // CHECK-LABEL: sil hidden @$S7ranking1XPA2A12GenericClassCySiGRbzrlE04testb16PropertyProtocolbC0yyxF |
| 254 | + func testGenericPropertyProtocolGenericClass(_ x: Self) { |
| 255 | + _ = self.foo // CHECK: class_method {{%.*}} : $GenericClass<Int>, #GenericClass.foo!getter.1 |
| 256 | + _ = self.bar // CHECK: function_ref @$S7ranking12GenericClassC3barxvg |
| 257 | + _ = self.baz() // CHECK: class_method {{%.*}} : $GenericClass<Int>, #GenericClass.baz |
| 258 | + _ = self[""] // CHECK: function_ref @$S7ranking12GenericClassCySiSScig |
| 259 | + } |
| 260 | +} |
| 261 | + |
| 262 | +extension X where Self : GenericClass<String> { |
| 263 | + // CHECK-LABEL: sil hidden @$S7ranking1XPA2A12GenericClassCySSGRbzrlE04testb16PropertyProtocolbC0yyxF |
| 264 | + func testGenericPropertyProtocolGenericClass(_ x: Self) { |
| 265 | + _ = self.foo // CHECK: class_method {{%.*}} : $GenericClass<String>, #GenericClass.foo!getter.1 |
| 266 | + _ = self.bar // CHECK: function_ref @$S7ranking12GenericClassC3barxvg |
| 267 | + _ = self.baz() // CHECK: class_method {{%.*}} : $GenericClass<String>, #GenericClass.baz |
| 268 | + _ = self[""] // CHECK: function_ref @$S7ranking12GenericClassCySiSScig |
| 269 | + } |
| 270 | +} |
0 commit comments