Skip to content

Commit 9af20c7

Browse files
committed
Evolution: Clean up superclass insertion tests a bit
- We don't want to support changing a root class of a class, so don't pretend that works. Some of these tests got removed recently in d8104e7 but one still remained. - For the tests that insert a non-root superclass in the inheritance hierarchy, also test calling a method of the derived class. This works now that we no longer hardcode vtable offsets and instead use dispatch thunks.
1 parent 2ef35ac commit 9af20c7

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

validation-test/Evolution/Inputs/class_insert_superclass.swift

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
open class Root {}
12

23
#if BEFORE
34

4-
open class FirstMiddle {
5+
open class FirstMiddle : Root {
56
let x: String
67

78
public init(x: String) {
@@ -13,7 +14,7 @@ open class FirstMiddle {
1314
}
1415
}
1516

16-
open class SecondMiddle {
17+
open class SecondMiddle : Root {
1718
let x: String
1819

1920
public init(x: String) {
@@ -25,7 +26,7 @@ open class SecondMiddle {
2526
}
2627
}
2728

28-
open class GenericMiddle<T> {
29+
open class GenericMiddle<T> : Root {
2930
let x: T
3031

3132
public init(x: T) {
@@ -40,7 +41,7 @@ open class GenericMiddle<T> {
4041
#else
4142

4243
// Insert concrete superclass
43-
open class Base {
44+
open class Base : Root {
4445
let x: String
4546

4647
public init(t: String) {
@@ -59,7 +60,7 @@ open class FirstMiddle : Base {
5960
}
6061

6162
// Insert generic superclass
62-
open class GenericBase<T> {
63+
open class GenericBase<T> : Root {
6364
let x: T
6465

6566
public init(t: T) {

validation-test/Evolution/test_class_resilient_superclass_methods.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ SuperclassMethodsTest.test("AddInterposingMethod") {
1616
override class func classMethod() -> String {
1717
return super.classMethod()
1818
}
19+
func newMethod() -> String {
20+
return "still works"
21+
}
1922
}
2023
if getVersion() == 0 {
2124
expectEqual(Leaf().method(), "Base.method()")
@@ -24,6 +27,7 @@ SuperclassMethodsTest.test("AddInterposingMethod") {
2427
expectEqual(Leaf().method(), "AddInterposingMethod.method()")
2528
expectEqual(Leaf.classMethod(), "AddInterposingMethod.classMethod()")
2629
}
30+
expectEqual(Leaf().newMethod(), "still works")
2731
}
2832
}
2933

@@ -36,6 +40,9 @@ SuperclassMethodsTest.test("RemoveInterposingMethod") {
3640
override class func classMethod() -> String {
3741
return super.classMethod()
3842
}
43+
func newMethod() -> String {
44+
return "still works"
45+
}
3946
}
4047
if getVersion() == 0 {
4148
expectEqual(Leaf().method(), "RemoveInterposingMethod.method()")
@@ -44,6 +51,7 @@ SuperclassMethodsTest.test("RemoveInterposingMethod") {
4451
expectEqual(Leaf().method(), "Base.method()")
4552
expectEqual(Leaf.classMethod(), "Base.classMethod()")
4653
}
54+
expectEqual(Leaf().newMethod(), "still works")
4755
}
4856
}
4957

@@ -56,6 +64,9 @@ SuperclassMethodsTest.test("InsertSuperclass") {
5664
override class func classMethod() -> String {
5765
return super.classMethod()
5866
}
67+
func newMethod() -> String {
68+
return "still works"
69+
}
5970
}
6071
if getVersion() == 0 {
6172
expectEqual(Leaf().method(), "Base.method()")
@@ -66,6 +77,7 @@ SuperclassMethodsTest.test("InsertSuperclass") {
6677
expectEqual(Leaf().nonOverriddenMethod(), "Base.nonOverriddenMethod()")
6778
expectEqual(Leaf.classMethod(), "InBetween.classMethod()")
6879
}
80+
expectEqual(Leaf().newMethod(), "still works")
6981
}
7082
}
7183

validation-test/Evolution/test_class_resilient_superclass_properties.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ SuperclassPropertiesTest.test("AddInterposingProperty") {
1616
override class var classProperty: String {
1717
return super.classProperty
1818
}
19+
var newProperty: String = "still works"
1920
}
2021
if getVersion() == 0 {
2122
expectEqual(Leaf().property, "Base.property")
@@ -24,6 +25,7 @@ SuperclassPropertiesTest.test("AddInterposingProperty") {
2425
expectEqual(Leaf().property, "AddInterposingProperty.property")
2526
expectEqual(Leaf.classProperty, "AddInterposingProperty.classProperty")
2627
}
28+
expectEqual(Leaf().newProperty, "still works")
2729
}
2830
}
2931

@@ -36,6 +38,7 @@ SuperclassPropertiesTest.test("RemoveInterposingProperty") {
3638
override class var classProperty: String {
3739
return super.classProperty
3840
}
41+
var newProperty: String = "still works"
3942
}
4043
if getVersion() == 0 {
4144
expectEqual(Leaf().property, "RemoveInterposingProperty.property")
@@ -44,6 +47,7 @@ SuperclassPropertiesTest.test("RemoveInterposingProperty") {
4447
expectEqual(Leaf().property, "Base.property")
4548
expectEqual(Leaf.classProperty, "Base.classProperty")
4649
}
50+
expectEqual(Leaf().newProperty, "still works")
4751
}
4852
}
4953

@@ -56,6 +60,7 @@ SuperclassPropertiesTest.test("InsertSuperclass") {
5660
override class var classProperty: String {
5761
return super.classProperty
5862
}
63+
var newProperty: String = "still works"
5964
}
6065
if getVersion() == 0 {
6166
expectEqual(Leaf().property, "Base.property")
@@ -66,6 +71,7 @@ SuperclassPropertiesTest.test("InsertSuperclass") {
6671
expectEqual(Leaf().nonOverriddenProperty, "Base.nonOverriddenProperty")
6772
expectEqual(Leaf.classProperty, "InBetween.classProperty")
6873
}
74+
expectEqual(Leaf().newProperty, "still works")
6975
}
7076
}
7177

0 commit comments

Comments
 (0)