Skip to content

Commit 6e8b0be

Browse files
committed
[interop][SwiftToCxx] add test to cover initializer in generic struct
1 parent d9f4c07 commit 6e8b0be

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

test/Interop/SwiftToCxx/generics/generic-struct-execution.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,22 @@ int main() {
7777
takeConcretePair(xprime);
7878
// CHECK-NEXT: CONCRETE pair of UInt32: 100000 918 ;
7979
}
80+
81+
{
82+
auto x = GenericPair<int, int>::init(11, 234242, 44);
83+
takeGenericPair(x);
84+
x.method();
85+
assert(x.getY() == 44);
86+
// CHECK-NEXT: GenericPair<T, T2>::init::11,44,234242;
87+
// CHECK-NEXT: GenericPair<Int32, Int32>(x: 11, y: 44)
88+
// CHECK-NEXT: GenericPair<T, T2>::testme::11,44;
89+
auto y = GenericPair<uint32_t, uint32_t>::init(0, -987, 3425);
90+
takeConcretePair(y);
91+
y.method();
92+
assert(y.getY() == 3425);
93+
// CHECK-NEXT: GenericPair<T, T2>::init::0,3425,-987;
94+
// CHECK-NEXT: CONCRETE pair of UInt32: 0 3425 ;
95+
// CHECK-NEXT: GenericPair<T, T2>::testme::0,3425;
96+
}
8097
return 0;
8198
}

test/Interop/SwiftToCxx/generics/generic-struct-in-cxx.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ public struct GenericPair<T, T2> {
1717
var x: T
1818
public var y: T2
1919

20+
init(x: T, y: T2) {
21+
self.x = x
22+
self.y = y
23+
}
24+
25+
public init(_ x: T, _ i: Int, _ y: T2) {
26+
self.x = x
27+
self.y = y
28+
print("GenericPair<T, T2>::init::\(x),\(y),\(i);")
29+
}
30+
2031
public func method() {
2132
let copyOfSelf = self
2233
print("GenericPair<T, T2>::testme::\(x),\(copyOfSelf.y);")
@@ -78,6 +89,7 @@ public func inoutConcretePair(_ x: UInt32, _ y: inout GenericPair<UInt32, UInt32
7889

7990
// CHECK: SWIFT_EXTERN void $s8Generics11GenericPairV1yq_vg(SWIFT_INDIRECT_RESULT void * _Nonnull, void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
8091
// CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV1yq_vs(const void * _Nonnull value, void * _Nonnull , SWIFT_CONTEXT void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
92+
// CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairVyACyxq_Gx_Siq_tcfC(SWIFT_INDIRECT_RESULT void * _Nonnull, const void * _Nonnull x, ptrdiff_t i, const void * _Nonnull y, void * _Nonnull , void * _Nonnull ) SWIFT_NOEXCEPT SWIFT_CALL; // init(_:_:_:)
8193
// CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV6methodyyF(void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // method()
8294
// CHECK-NEXT: SWIFT_EXTERN void $s8Generics11GenericPairV14mutatingMethodyyACyq_xGF(const void * _Nonnull other, void * _Nonnull , SWIFT_CONTEXT void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // mutatingMethod(_:)
8395
// CHECK-NEXT: SWIFT_EXTERN ptrdiff_t $s8Generics11GenericPairV12computedPropSivg(void * _Nonnull , SWIFT_CONTEXT const void * _Nonnull _self) SWIFT_NOEXCEPT SWIFT_CALL; // _
@@ -224,6 +236,13 @@ public func inoutConcretePair(_ x: UInt32, _ y: inout GenericPair<UInt32, UInt32
224236
// CHECK-NEXT: }
225237
// CHECK-NEXT: template<class T_0_0, class T_0_1>
226238
// CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0> && swift::isUsableInGenericContext<T_0_1>
239+
// CHECK-NEXT: inline GenericPair<T_0_0, T_0_1> GenericPair<T_0_0, T_0_1>::init(const T_0_0& x, swift::Int i, const T_0_1& y) {
240+
// CHECK-NEXT: return _impl::_impl_GenericPair<T_0_0, T_0_1>::returnNewValue([&](void * _Nonnull result) {
241+
// CHECK-NEXT: _impl::$s8Generics11GenericPairVyACyxq_Gx_Siq_tcfC(result, swift::_impl::getOpaquePointer(x), i, swift::_impl::getOpaquePointer(y), swift::TypeMetadataTrait<T_0_0>::getTypeMetadata(), swift::TypeMetadataTrait<T_0_1>::getTypeMetadata());
242+
// CHECK-NEXT: });
243+
// CHECK-NEXT: }
244+
// CHECK-NEXT: template<class T_0_0, class T_0_1>
245+
// CHECK-NEXT: requires swift::isUsableInGenericContext<T_0_0> && swift::isUsableInGenericContext<T_0_1>
227246
// CHECK-NEXT: inline void GenericPair<T_0_0, T_0_1>::method() const {
228247
// CHECK-NEXT: return _impl::$s8Generics11GenericPairV6methodyyF(swift::TypeMetadataTrait<GenericPair<T_0_0, T_0_1>>::getTypeMetadata(), _getOpaquePointer());
229248
// CHECK-NEXT: }

0 commit comments

Comments
 (0)