Skip to content

Commit 372f7ee

Browse files
committed
[interop][SwiftToCxx] add a test for class property setters
1 parent 3873603 commit 372f7ee

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

test/Interop/SwiftToCxx/properties/setter-in-cxx-execution.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,13 @@ int main() {
4747

4848
smallStructWithProps.setLargeStructWithProps(largeStructWithProps);
4949
// CHECK-NEXT: SET: LargeStruct(x1: 0, x2: 2, x3: -72, x4: 3, x5: 4, x6: 5), FirstSmallStruct(x: 999)
50+
51+
auto propsInClass = createPropsInClass(-1234);
52+
assert(propsInClass.getStoredInt() == -1234);
53+
propsInClass.setStoredInt(45);
54+
assert(propsInClass.getStoredInt() == 45);
55+
propsInClass.setComputedInt(-11);
56+
assert(propsInClass.getComputedInt() == -11);
57+
assert(propsInClass.getStoredInt() == -13);
5058
return 0;
5159
}

test/Interop/SwiftToCxx/properties/setter-in-cxx.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,46 @@ public struct LargeStructWithProps {
7979
// CHECK-NEXT: return _impl::$s10Properties20LargeStructWithPropsV011storedSmallC0AA05FirstgC0Vvs(_impl::swift_interop_passDirect_Properties_FirstSmallStruct(_impl::_impl_FirstSmallStruct::getOpaquePointer(value)), _getOpaquePointer());
8080
// CHECK-NEXT: }
8181

82+
public final class PropertiesInClass {
83+
public var storedInt: Int32
84+
85+
init(_ x: Int32) {
86+
storedInt = x
87+
}
88+
89+
public var computedInt: Int {
90+
get {
91+
return Int(storedInt) + 2
92+
} set {
93+
storedInt = Int32(newValue - 2)
94+
}
95+
}
96+
}
97+
98+
// CHECK: class PropertiesInClass final : public swift::_impl::RefCountedClass {
99+
// CHECK: using RefCountedClass::operator=;
100+
// CHECK-NEXT: inline int32_t getStoredInt();
101+
// CHECK-NEXT: inline void setStoredInt(int32_t value);
102+
// CHECK-NEXT: inline swift::Int getComputedInt();
103+
// CHECK-NEXT: inline void setComputedInt(swift::Int newValue);
104+
105+
// CHECK: inline int32_t PropertiesInClass::getStoredInt() {
106+
// CHECK-NEXT: return _impl::$s10Properties0A7InClassC9storedInts5Int32Vvg(::swift::_impl::_impl_RefCountedClass::getOpaquePointer(*this));
107+
// CHECK-NEXT: }
108+
// CHECK-NEXT: inline void PropertiesInClass::setStoredInt(int32_t value) {
109+
// CHECK-NEXT: return _impl::$s10Properties0A7InClassC9storedInts5Int32Vvs(value, ::swift::_impl::_impl_RefCountedClass::getOpaquePointer(*this));
110+
// CHECK-NEXT: }
111+
// CHECK-NEXT: inline swift::Int PropertiesInClass::getComputedInt() {
112+
// CHECK-NEXT: return _impl::$s10Properties0A7InClassC11computedIntSivg(::swift::_impl::_impl_RefCountedClass::getOpaquePointer(*this));
113+
// CHECK-NEXT: }
114+
// CHECK-NEXT: inline void PropertiesInClass::setComputedInt(swift::Int newValue) {
115+
// CHECK-NEXT: return _impl::$s10Properties0A7InClassC11computedIntSivs(newValue, ::swift::_impl::_impl_RefCountedClass::getOpaquePointer(*this));
116+
// CHECK-NEXT: }
117+
118+
public func createPropsInClass(_ x: Int32) -> PropertiesInClass {
119+
return PropertiesInClass(x)
120+
}
121+
82122
public struct SmallStructWithProps {
83123
public var storedInt: UInt32
84124
public var computedInt: Int {

0 commit comments

Comments
 (0)