Skip to content

Commit 6a45971

Browse files
committed
[IRGen/Resilience] Add a test case for rdar://problem/36560486
Since field offsets are now encoded after generic parameters, it is useful to validate that using generic parameter metadata is now more resilient in presence of new fields.
1 parent 238b876 commit 6a45971

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
public func getVersion() -> Int {
3+
#if BEFORE
4+
return 0
5+
#else
6+
return 1
7+
#endif
8+
}
9+
10+
public protocol P {
11+
static func compute() -> Int
12+
}
13+
14+
public struct A : P {
15+
public init() {}
16+
17+
public static func compute() -> Int {
18+
return 42
19+
}
20+
}
21+
22+
#if BEFORE
23+
24+
public struct S<T: P> {
25+
public init() {}
26+
}
27+
28+
#else
29+
30+
public struct S<T: P> {
31+
public init() {
32+
question = "Ultimate Question"
33+
}
34+
35+
public var question: String
36+
}
37+
38+
#endif
39+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-resilience-test
2+
// REQUIRES: executable_test
3+
4+
import StdlibUnittest
5+
import generic_resilient_struct_add_property
6+
7+
extension S {
8+
public func answer() -> Int {
9+
return T.compute()
10+
}
11+
}
12+
13+
var GenericStructAddPropertyTest = TestSuite("GenericStructAddPropertyTest")
14+
GenericStructAddPropertyTest.test("AddStoredProperty") {
15+
let s = S<A>()
16+
expectEqual(s.answer(), 42)
17+
}
18+
19+
runAllTests()

0 commit comments

Comments
 (0)