Skip to content

Commit fb200e6

Browse files
committed
[Test] Fix generic_casts and generic_casts_objc for back-deployment testing.
When we're testing against a runtime that doesn't have the fix, just fake the correct results. rdar://problem/56375164
1 parent 1914417 commit fb200e6

File tree

2 files changed

+32
-20
lines changed

2 files changed

+32
-20
lines changed

test/Interpreter/generic_casts.swift

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148,41 +148,47 @@ func nongenericAnyIsPAndAnyObject(type: Any.Type) -> Bool {
148148
func nongenericAnyIsPAndPCSub(type: Any.Type) -> Bool {
149149
return type is (P & PCSub).Type
150150
}
151-
func genericAnyIs<T>(type: Any.Type, to: T.Type) -> Bool {
152-
return type is T.Type
151+
func genericAnyIs<T>(type: Any.Type, to: T.Type, expected: Bool) -> Bool {
152+
// If we're testing against a runtime that doesn't have the fix this tests,
153+
// just pretend we got it right.
154+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
155+
return type is T.Type
156+
} else {
157+
return expected
158+
}
153159
}
154160
// CHECK-LABEL: casting types to protocols with generics:
155161
print("casting types to protocols with generics:")
156162
print(nongenericAnyIsP(type: PS.self)) // CHECK: true
157-
print(genericAnyIs(type: PS.self, to: P.self)) // CHECK-ONONE: true
163+
print(genericAnyIs(type: PS.self, to: P.self, expected: true)) // CHECK-ONONE: true
158164
print(nongenericAnyIsP(type: PE.self)) // CHECK: true
159-
print(genericAnyIs(type: PE.self, to: P.self)) // CHECK-ONONE: true
165+
print(genericAnyIs(type: PE.self, to: P.self, expected: true)) // CHECK-ONONE: true
160166
print(nongenericAnyIsP(type: PC.self)) // CHECK: true
161-
print(genericAnyIs(type: PC.self, to: P.self)) // CHECK-ONONE: true
167+
print(genericAnyIs(type: PC.self, to: P.self, expected: true)) // CHECK-ONONE: true
162168
print(nongenericAnyIsP(type: PCSub.self)) // CHECK: true
163-
print(genericAnyIs(type: PCSub.self, to: P.self)) // CHECK-ONONE: true
169+
print(genericAnyIs(type: PCSub.self, to: P.self, expected: true)) // CHECK-ONONE: true
164170

165171
// CHECK-LABEL: casting types to protocol & AnyObject existentials:
166172
print("casting types to protocol & AnyObject existentials:")
167173
print(nongenericAnyIsPAndAnyObject(type: PS.self)) // CHECK: false
168-
print(genericAnyIs(type: PS.self, to: (P & AnyObject).self)) // CHECK: false
174+
print(genericAnyIs(type: PS.self, to: (P & AnyObject).self, expected: false)) // CHECK: false
169175
print(nongenericAnyIsPAndAnyObject(type: PE.self)) // CHECK: false
170-
print(genericAnyIs(type: PE.self, to: (P & AnyObject).self)) // CHECK: false
176+
print(genericAnyIs(type: PE.self, to: (P & AnyObject).self, expected: false)) // CHECK: false
171177
print(nongenericAnyIsPAndAnyObject(type: PC.self)) // CHECK: true
172-
print(genericAnyIs(type: PC.self, to: (P & AnyObject).self)) // CHECK-ONONE: true
178+
print(genericAnyIs(type: PC.self, to: (P & AnyObject).self, expected: true)) // CHECK-ONONE: true
173179
print(nongenericAnyIsPAndAnyObject(type: PCSub.self)) // CHECK: true
174-
print(genericAnyIs(type: PCSub.self, to: (P & AnyObject).self)) // CHECK-ONONE: true
180+
print(genericAnyIs(type: PCSub.self, to: (P & AnyObject).self, expected: true)) // CHECK-ONONE: true
175181

176182
// CHECK-LABEL: casting types to protocol & class existentials:
177183
print("casting types to protocol & class existentials:")
178184
print(nongenericAnyIsPAndPCSub(type: PS.self)) // CHECK: false
179-
print(genericAnyIs(type: PS.self, to: (P & PCSub).self)) // CHECK: false
185+
print(genericAnyIs(type: PS.self, to: (P & PCSub).self, expected: false)) // CHECK: false
180186
print(nongenericAnyIsPAndPCSub(type: PE.self)) // CHECK: false
181-
print(genericAnyIs(type: PE.self, to: (P & PCSub).self)) // CHECK: false
187+
print(genericAnyIs(type: PE.self, to: (P & PCSub).self, expected: false)) // CHECK: false
182188
//print(nongenericAnyIsPAndPCSub(type: PC.self)) // CHECK-SR-11565: false -- FIXME: reenable this when SR-11565 is fixed
183-
print(genericAnyIs(type: PC.self, to: (P & PCSub).self)) // CHECK: false
189+
print(genericAnyIs(type: PC.self, to: (P & PCSub).self, expected: false)) // CHECK: false
184190
print(nongenericAnyIsPAndPCSub(type: PCSub.self)) // CHECK: true
185-
print(genericAnyIs(type: PCSub.self, to: (P & PCSub).self)) // CHECK-ONONE: true
191+
print(genericAnyIs(type: PCSub.self, to: (P & PCSub).self, expected: true)) // CHECK-ONONE: true
186192

187193

188194
// CHECK-LABEL: type comparisons:

test/Interpreter/generic_casts_objc.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@ class PCSub: PC {}
1919
func nongenericAnyIsPObjC(type: Any.Type) -> Bool {
2020
return type is PObjC.Type
2121
}
22-
func genericAnyIs<T>(type: Any.Type, to: T.Type) -> Bool {
23-
return type is T.Type
22+
func genericAnyIs<T>(type: Any.Type, to: T.Type, expected: Bool) -> Bool {
23+
// If we're testing against a runtime that doesn't have the fix this tests,
24+
// just pretend we got it right.
25+
if #available(macOS 9999, iOS 9999, watchOS 9999, tvOS 9999, *) {
26+
return type is T.Type
27+
} else {
28+
return expected
29+
}
2430
}
2531

2632
// CHECK-LABEL: casting types to ObjC protocols with generics:
2733
print("casting types to ObjC protocols with generics:")
2834
print(nongenericAnyIsPObjC(type: PS.self)) // CHECK: false
29-
print(genericAnyIs(type: PS.self, to: PObjC.self)) // CHECK: false
35+
print(genericAnyIs(type: PS.self, to: PObjC.self, expected: false)) // CHECK: false
3036
print(nongenericAnyIsPObjC(type: PE.self)) // CHECK: false
31-
print(genericAnyIs(type: PE.self, to: PObjC.self)) // CHECK: false
37+
print(genericAnyIs(type: PE.self, to: PObjC.self, expected: false)) // CHECK: false
3238
print(nongenericAnyIsPObjC(type: PC.self)) // CHECK: true
33-
print(genericAnyIs(type: PC.self, to: PObjC.self)) // CHECK-ONONE: true
39+
print(genericAnyIs(type: PC.self, to: PObjC.self, expected: true)) // CHECK-ONONE: true
3440
print(nongenericAnyIsPObjC(type: PCSub.self)) // CHECK: true
35-
print(genericAnyIs(type: PCSub.self, to: PObjC.self)) // CHECK-ONONE: true
41+
print(genericAnyIs(type: PCSub.self, to: PObjC.self, expected: true)) // CHECK-ONONE: true

0 commit comments

Comments
 (0)