Skip to content

Commit c11ed9e

Browse files
committed
Executable test for runtime demangling of pack expansions
1 parent 802c986 commit c11ed9e

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking)
2+
3+
// REQUIRES: executable_test
4+
5+
// UNSUPPORTED: use_os_stdlib
6+
// UNSUPPORTED: back_deployment_runtime
7+
8+
import StdlibUnittest
9+
10+
var conformances = TestSuite("VariadicGenericConformances")
11+
12+
protocol P {
13+
associatedtype A
14+
associatedtype B
15+
associatedtype C
16+
}
17+
18+
struct H<T> {}
19+
struct G<each T> {}
20+
21+
struct TupleWitnesses<each T: Sequence>: P {
22+
typealias A = (Bool, repeat each T)
23+
typealias B = (repeat each T.Element, x: Bool)
24+
typealias C = (x: Bool, repeat H<each T.Element>)
25+
}
26+
27+
struct SingletonTupleWitnesses<each T>: P {
28+
typealias A = (repeat each T)
29+
typealias B = (repeat each T, Int)
30+
typealias C = (Int, repeat each T)
31+
}
32+
33+
struct FunctionWitnesses<each T: Sequence>: P {
34+
typealias A = (Bool, repeat each T) -> ()
35+
typealias B = (repeat each T.Element, Bool) -> ()
36+
typealias C = (Bool, repeat H<each T.Element>) -> ()
37+
}
38+
39+
struct NominalWitnesses<each T: Sequence>: P {
40+
typealias A = G<Bool, repeat each T>
41+
typealias B = G<repeat each T.Element, Bool>
42+
typealias C = G<Bool, repeat H<each T.Element>>
43+
}
44+
45+
func getA<T: P>(_: T.Type) -> Any.Type {
46+
return T.A.self
47+
}
48+
49+
func getB<T: P>(_: T.Type) -> Any.Type {
50+
return T.B.self
51+
}
52+
53+
func getC<T: P>(_: T.Type) -> Any.Type {
54+
return T.C.self
55+
}
56+
57+
conformances.test("tupleWitnesses") {
58+
let g = TupleWitnesses<Array<Int>, Set<String>>.self
59+
expectEqual((Bool, Array<Int>, Set<String>).self, getA(g))
60+
expectEqual((Int, String, x: Bool).self, getB(g))
61+
expectEqual((x: Bool, H<Int>, H<String>).self, getC(g))
62+
}
63+
64+
conformances.test("singletonTupleWitnesses") {
65+
let g1 = SingletonTupleWitnesses<Bool>.self
66+
// FIXME: Unwrap one-element tuples
67+
// expectEqual(Bool.self, getA(g1))
68+
69+
let g2 = SingletonTupleWitnesses< >.self
70+
// FIXME: Unwrap one-element tuples
71+
// expectEqual(Int.self, getB(g2))
72+
// expectEqual(Int.self, getC(g2))
73+
}
74+
75+
conformances.test("functionWitnesses") {
76+
let g = FunctionWitnesses<Array<Int>, Set<String>>.self
77+
expectEqual(((Bool, Array<Int>, Set<String>) -> ()).self, getA(g))
78+
expectEqual(((Int, String, Bool) -> ()).self, getB(g))
79+
expectEqual(((Bool, H<Int>, H<String>) -> ()).self, getC(g))
80+
}
81+
82+
conformances.test("nominalWitnesses") {
83+
let g = NominalWitnesses<Array<Int>, Set<String>>.self
84+
expectEqual(G<Bool, Array<Int>, Set<String>>.self, getA(g))
85+
expectEqual(G<Int, String, Bool>.self, getB(g))
86+
expectEqual(G<Bool, H<Int>, H<String>>.self, getC(g))
87+
}
88+
89+
runAllTests()

0 commit comments

Comments
 (0)