Skip to content

Commit 161ea99

Browse files
author
Harlan Haskins
committed
Add SILGen test for usage of dynamic accessors in and out of interfaces
1 parent b7ecb92 commit 161ea99

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

test/SILGen/dynamic_accessors.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o /dev/null -disable-objc-attr-requires-foundation-module -emit-interface-path %t/dynamic_accessors.swiftinterface %s
3+
// RUN: %target-swift-emit-silgen -disable-objc-attr-requires-foundation-module %s | %FileCheck %s
4+
// RUN: %target-swift-frontend -emit-silgen -disable-objc-attr-requires-foundation-module %t/dynamic_accessors.swiftinterface | %FileCheck %s
5+
6+
public class MyObjCClass {
7+
@objc public dynamic var a: Int {
8+
// CHECK-LABEL: sil [thunk] @$s17dynamic_accessors11MyObjCClassC1aSivgTo : $@convention(objc_method) (MyObjCClass) -> Int {
9+
// CHECK: function_ref @$s17dynamic_accessors11MyObjCClassC1aSivg
10+
// CHECK: }
11+
get { return 4 }
12+
13+
// CHECK-LABEL sil [thunk] @$s17dynamic_accessors11MyObjCClassC1aSivsTo : $@convention(objc_method) (Int, MyObjCClass) -> () {
14+
// CHECK: function_ref @$s17dynamic_accessors11MyObjCClassC1aSivs
15+
// CHECK: }
16+
set {}
17+
}
18+
19+
@objc public dynamic subscript(x: Int) -> Int {
20+
// CHECK-LABEL: sil [thunk] @$s17dynamic_accessors11MyObjCClassCyS2icigTo : $@convention(objc_method) (Int, MyObjCClass) -> Int {
21+
// CHECK: function_ref @$s17dynamic_accessors11MyObjCClassCyS2icig
22+
// CHECK: }
23+
get { return x }
24+
25+
// CHECK-LABEL: sil [thunk] @$s17dynamic_accessors11MyObjCClassCyS2icisTo : $@convention(objc_method) (Int, Int, MyObjCClass) -> () {
26+
// CHECK: function_ref @$s17dynamic_accessors11MyObjCClassCyS2icis
27+
// CHECK: }
28+
set {}
29+
}
30+
31+
public init() {}
32+
}
33+
34+
@inlinable public func foo() {
35+
let x = MyObjCClass()
36+
// CHECK: objc_method %{{[0-9]+}} : $MyObjCClass, #MyObjCClass.a!getter.1.foreign
37+
// CHECK: objc_method %{{[0-9]+}} : $MyObjCClass, #MyObjCClass.a!setter.1.foreign
38+
x.a = x.a + 1
39+
40+
// CHECK: objc_method %{{[0-9]+}} : $MyObjCClass, #MyObjCClass.subscript!getter.1.foreign
41+
// CHECK: objc_method %{{[0-9]+}} : $MyObjCClass, #MyObjCClass.subscript!setter.1.foreign
42+
x[4] = x[5]
43+
}

0 commit comments

Comments
 (0)