Skip to content

Commit 21c15d8

Browse files
committed
Update validation tests for id-as-Any.
1 parent 5bfd6cc commit 21c15d8

13 files changed

+114
-111
lines changed

test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class TestObjCKeyTy : NSObject, NSCopying {
8484
}
8585

8686
@objc(copyWithZone:)
87-
func copy(with zone: NSZone?) -> AnyObject {
87+
func copy(with zone: NSZone?) -> Any {
8888
return TestObjCKeyTy(value)
8989
}
9090

@@ -93,7 +93,7 @@ class TestObjCKeyTy : NSObject, NSCopying {
9393
return value.description
9494
}
9595

96-
override func isEqual(_ object: AnyObject!) -> Bool {
96+
override func isEqual(_ object: Any!) -> Bool {
9797
if let other = object {
9898
if let otherObjcKey = other as? TestObjCKeyTy {
9999
return self.value == otherObjcKey.value
@@ -136,7 +136,7 @@ class TestObjCInvalidKeyTy {
136136
}
137137

138138
@objc
139-
func isEqual(_ object: AnyObject!) -> Bool {
139+
func isEqual(_ object: Any!) -> Bool {
140140
fatalError()
141141
}
142142

@@ -207,7 +207,7 @@ class TestObjCEquatableValueTy : NSObject {
207207
serial = -serial
208208
}
209209

210-
override func isEqual(_ object: AnyObject!) -> Bool {
210+
override func isEqual(_ object: Any!) -> Bool {
211211
if let other = object {
212212
if let otherObjcKey = other as? TestObjCEquatableValueTy {
213213
return self.value == otherObjcKey.value
@@ -586,7 +586,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
586586
}
587587
for i in 0..<returnedCount {
588588
let key: AnyObject = state.itemsPtr![i]!
589-
let value: AnyObject = d.object(forKey: key)!
589+
let value: AnyObject = d.object(forKey: key)! as AnyObject
590590
let kv = (key, value)
591591
sink(kv)
592592
itemsReturned += 1
@@ -611,7 +611,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
611611
slurpFastEnumerationFromSwift(
612612
a, enumerator, sink, maxItems: maxFastEnumerationItems)
613613
while let value = enumerator.nextObject() {
614-
sink(value)
614+
sink(value as AnyObject)
615615
}
616616
}
617617

@@ -623,8 +623,8 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
623623
slurpFastEnumerationFromSwift(
624624
d, enumerator, sink, maxItems: maxFastEnumerationItems)
625625
while let key = enumerator.nextObject() {
626-
let value: AnyObject = d.object(forKey: key)!
627-
let kv = (key, value)
626+
let value: AnyObject = d.object(forKey: key)! as AnyObject
627+
let kv = (key as AnyObject, value)
628628
sink(kv)
629629
}
630630
}
@@ -635,7 +635,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
635635
let objcValues = NSMutableArray()
636636
slurpFastEnumerationOfArrayFromObjCImpl(a, fe, objcValues)
637637
for value in objcValues {
638-
sink(value)
638+
sink(value as AnyObject)
639639
}
640640
}
641641

@@ -759,7 +759,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
759759
let objcValues = NSMutableArray()
760760
slurpFastEnumerationOfArrayFromObjCImpl(s, fe, objcValues)
761761
for value in objcValues {
762-
sink(value)
762+
sink(value as AnyObject)
763763
}
764764
}
765765

@@ -770,7 +770,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
770770
slurpFastEnumerationFromSwift(
771771
s, enumerator, sink, maxItems: maxFastEnumerationItems)
772772
while let value = enumerator.nextObject() {
773-
sink(value)
773+
sink(value as AnyObject)
774774
}
775775
}
776776

@@ -862,8 +862,8 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
862862
let objcPairs = NSMutableArray()
863863
slurpFastEnumerationOfDictionaryFromObjCImpl(d, fe, objcPairs)
864864
for i in 0..<objcPairs.count/2 {
865-
let key: AnyObject = objcPairs[i * 2]
866-
let value: AnyObject = objcPairs[i * 2 + 1]
865+
let key = objcPairs[i * 2] as AnyObject
866+
let value = objcPairs[i * 2 + 1] as AnyObject
867867
let kv = (key, value)
868868
sink(kv)
869869
}

validation-test/StdlibUnittest/FoundationExtras.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ FoundationExtrasTests.test("withOverriddenLocaleCurrentLocale(Locale)") {
1616
// these locales happens to be the same as the actual current locale.
1717
do {
1818
let result = withOverriddenLocaleCurrentLocale(
19-
Locale(identifier: "en_US")) {
19+
Locale(identifier: "en_US") as NSLocale) {
2020
() -> Int in
2121
expectEqual("en_US", Locale.current.identifier)
2222
return 42
@@ -25,7 +25,7 @@ FoundationExtrasTests.test("withOverriddenLocaleCurrentLocale(Locale)") {
2525
}
2626
do {
2727
let result = withOverriddenLocaleCurrentLocale(
28-
Locale(identifier: "uk")) {
28+
Locale(identifier: "uk") as NSLocale) {
2929
() -> Int in
3030
expectEqual("uk", Locale.current.identifier)
3131
return 42
@@ -36,13 +36,13 @@ FoundationExtrasTests.test("withOverriddenLocaleCurrentLocale(Locale)") {
3636

3737
FoundationExtrasTests.test("withOverriddenLocaleCurrentLocale(Locale)/nested") {
3838
withOverriddenLocaleCurrentLocale(
39-
Locale(identifier: "uk")) {
39+
Locale(identifier: "uk") as NSLocale) {
4040
() -> Void in
4141

4242
expectCrashLater()
4343

4444
withOverriddenLocaleCurrentLocale(
45-
Locale(identifier: "uk")) {
45+
Locale(identifier: "uk") as NSLocale) {
4646
() -> Void in
4747

4848
return ()

validation-test/compiler_crashers_fixed/00324-swift-shortcircuit-isequal.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import Foundation
1717
class Test: NSObject {
18-
override func isEqual(_ object: AnyObject?) -> Bool {
18+
override func isEqual(_ object: Any?) -> Bool {
1919
return false && super.isEqual(object)
2020
}
2121
}

validation-test/stdlib/ArrayBridging.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ struct ArrayBridge_objectAtIndex_RaceTest : RaceTestWithPerTrialData {
3939
_ raceData: RaceData, _ threadLocalData: inout ThreadLocalData
4040
) -> Observation {
4141
let nsa = raceData.nsa
42-
let v: AnyObject = nsa.object(at: 0)
42+
let v = nsa.object(at: 0) as AnyObject
4343
return Observation(unsafeBitCast(v, to: UInt.self))
4444
}
4545

@@ -79,10 +79,10 @@ struct ArrayBridge_FastEnumeration_ObjC_RaceTest :
7979
let objcValues = NSMutableArray()
8080
slurpFastEnumerationOfArrayFromObjCImpl(nsa, nsa, objcValues)
8181
return Observation(
82-
unsafeBitCast(objcValues[0], to: UInt.self),
83-
unsafeBitCast(objcValues[1], to: UInt.self),
84-
unsafeBitCast(objcValues[2], to: UInt.self),
85-
unsafeBitCast(objcValues[3], to: UInt.self))
82+
unsafeBitCast(objcValues[0] as AnyObject, to: UInt.self),
83+
unsafeBitCast(objcValues[1] as AnyObject, to: UInt.self),
84+
unsafeBitCast(objcValues[2] as AnyObject, to: UInt.self),
85+
unsafeBitCast(objcValues[3] as AnyObject, to: UInt.self))
8686
}
8787

8888
func evaluateObservations(

validation-test/stdlib/ArrayNew.swift.gyb

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,13 @@ class CustomImmutableNSArray : NSArray {
291291
}
292292

293293
@objc(copyWithZone:)
294-
override func copy(with zone: NSZone?) -> AnyObject {
294+
override func copy(with zone: NSZone?) -> Any {
295295
CustomImmutableNSArray.timesCopyWithZoneWasCalled += 1
296296
return self
297297
}
298298

299299
@objc
300-
override func object(at index: Int) -> AnyObject {
300+
override func object(at index: Int) -> Any {
301301
CustomImmutableNSArray.timesObjectAtIndexWasCalled += 1
302302
return _data[index]
303303
}
@@ -535,22 +535,22 @@ for index in [ -100, -1, 3, 4, 100 ] {
535535
ArrayTestSuite.test("BridgedToObjC/Verbatim/objectAtIndex") {
536536
let a = getBridgedNSArrayOfRefTypeVerbatimBridged(numElements: 3)
537537

538-
var v: AnyObject = a.object(at: 0)
538+
var v: AnyObject = a.object(at: 0) as AnyObject
539539
expectEqual(10, (v as! TestObjCValueTy).value)
540540
let idValue0 = unsafeBitCast(v, to: UInt.self)
541541

542-
v = a.object(at: 1)
542+
v = a.object(at: 1) as AnyObject
543543
expectEqual(20, (v as! TestObjCValueTy).value)
544544
let idValue1 = unsafeBitCast(v, to: UInt.self)
545545

546-
v = a.object(at: 2)
546+
v = a.object(at: 2) as AnyObject
547547
expectEqual(30, (v as! TestObjCValueTy).value)
548548
let idValue2 = unsafeBitCast(v, to: UInt.self)
549549

550550
for i in 0..<3 {
551-
expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self))
552-
expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self))
553-
expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self))
551+
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
552+
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
553+
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
554554
}
555555

556556
expectAutoreleasedKeysAndValues(unopt: (0, 3))
@@ -608,9 +608,9 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/getObjects") {
608608
let idValue2 = unsafeBitCast(v, to: UInt.self)
609609

610610
for i in 0..<3 {
611-
expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self))
612-
expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self))
613-
expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self))
611+
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
612+
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
613+
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
614614
}
615615

616616
buffer.deallocate(capacity: 3)
@@ -621,7 +621,7 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/getObjects") {
621621

622622
ArrayTestSuite.test("BridgedToObjC/Verbatim/copyWithZone") {
623623
let a = getBridgedNSArrayOfRefTypeVerbatimBridged(numElements: 3)
624-
let copy: AnyObject = a.copy(with: nil)
624+
let copy: AnyObject = a.copy(with: nil) as AnyObject
625625
expectEqual(
626626
unsafeBitCast(a, to: UInt.self), unsafeBitCast(copy, to: UInt.self))
627627
}
@@ -707,15 +707,15 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/ObjectEnumerator/FastEnumeration/Use
707707
ArrayTestSuite.test("BridgedToObjC/Verbatim/BridgeBack/Reallocate") {
708708
let a = getBridgedNSArrayOfRefTypeVerbatimBridged(numElements: 3)
709709

710-
var v: AnyObject = a[0]
710+
var v: AnyObject = a[0] as AnyObject
711711
expectEqual(10, (v as! TestObjCValueTy).value)
712712
let idValue0 = unsafeBitCast(v, to: UInt.self)
713713

714-
v = a[1]
714+
v = a[1] as AnyObject
715715
expectEqual(20, (v as! TestObjCValueTy).value)
716716
let idValue1 = unsafeBitCast(v, to: UInt.self)
717717

718-
v = a[2]
718+
v = a[2] as AnyObject
719719
expectEqual(30, (v as! TestObjCValueTy).value)
720720
let idValue2 = unsafeBitCast(v, to: UInt.self)
721721

@@ -731,9 +731,9 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/BridgeBack/Reallocate") {
731731

732732
// Check that mutating the native array did not affect the bridged array.
733733
expectEqual(3, a.count)
734-
expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self))
735-
expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self))
736-
expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self))
734+
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
735+
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
736+
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
737737

738738
expectAutoreleasedKeysAndValues(unopt: (0, 3))
739739
}
@@ -808,22 +808,22 @@ for index in [ -100, -1, 3, 4, 100 ] {
808808
ArrayTestSuite.test("BridgedToObjC/Custom/objectAtIndex") {
809809
let a = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3)
810810

811-
var v: AnyObject = a.object(at: 0)
811+
var v: AnyObject = a.object(at: 0) as AnyObject
812812
expectEqual(10, (v as! TestObjCValueTy).value)
813813
let idValue0 = unsafeBitCast(v, to: UInt.self)
814814

815-
v = a.object(at: 1)
815+
v = a.object(at: 1) as AnyObject
816816
expectEqual(20, (v as! TestObjCValueTy).value)
817817
let idValue1 = unsafeBitCast(v, to: UInt.self)
818818

819-
v = a.object(at: 2)
819+
v = a.object(at: 2) as AnyObject
820820
expectEqual(30, (v as! TestObjCValueTy).value)
821821
let idValue2 = unsafeBitCast(v, to: UInt.self)
822822

823823
for i in 0..<3 {
824-
expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self))
825-
expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self))
826-
expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self))
824+
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
825+
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
826+
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
827827
}
828828

829829
expectEqual(3, TestBridgedValueTy.bridgeOperations)
@@ -882,9 +882,9 @@ ArrayTestSuite.test("BridgedToObjC/Custom/getObjects") {
882882
let idValue2 = unsafeBitCast(v, to: UInt.self)
883883

884884
for i in 0..<3 {
885-
expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self))
886-
expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self))
887-
expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self))
885+
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
886+
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
887+
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
888888
}
889889

890890
buffer.deallocate(capacity: 3)
@@ -896,7 +896,7 @@ ArrayTestSuite.test("BridgedToObjC/Custom/getObjects") {
896896

897897
ArrayTestSuite.test("BridgedToObjC/Custom/copyWithZone") {
898898
let a = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3)
899-
let copy: AnyObject = a.copy(with: nil)
899+
let copy: AnyObject = a.copy(with: nil) as AnyObject
900900
expectEqual(
901901
unsafeBitCast(a, to: UInt.self),
902902
unsafeBitCast(copy, to: UInt.self))
@@ -1001,15 +1001,15 @@ ArrayTestSuite.test("BridgedToObjC/Custom/ObjectEnumerator/FastEnumeration/UseFr
10011001
ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Cast") {
10021002
let a = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3)
10031003

1004-
var v: AnyObject = a[0]
1004+
var v: AnyObject = a[0] as AnyObject
10051005
expectEqual(10, (v as! TestObjCValueTy).value)
10061006
let idValue0 = unsafeBitCast(v, to: UInt.self)
10071007

1008-
v = a[1]
1008+
v = a[1] as AnyObject
10091009
expectEqual(20, (v as! TestObjCValueTy).value)
10101010
let idValue1 = unsafeBitCast(v, to: UInt.self)
10111011

1012-
v = a[2]
1012+
v = a[2] as AnyObject
10131013
expectEqual(30, (v as! TestObjCValueTy).value)
10141014
let idValue2 = unsafeBitCast(v, to: UInt.self)
10151015

@@ -1025,25 +1025,25 @@ ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Cast") {
10251025

10261026
// Check that mutating the native array did not affect the bridged array.
10271027
expectEqual(3, a.count)
1028-
expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self))
1029-
expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self))
1030-
expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self))
1028+
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
1029+
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
1030+
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
10311031

10321032
expectAutoreleasedKeysAndValues(unopt: (0, 3))
10331033
}
10341034

10351035
ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Reallocate") {
10361036
let a = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3)
10371037

1038-
var v: AnyObject = a[0]
1038+
var v: AnyObject = a[0] as AnyObject
10391039
expectEqual(10, (v as! TestObjCValueTy).value)
10401040
let idValue0 = unsafeBitCast(v, to: UInt.self)
10411041

1042-
v = a[1]
1042+
v = a[1] as AnyObject
10431043
expectEqual(20, (v as! TestObjCValueTy).value)
10441044
let idValue1 = unsafeBitCast(v, to: UInt.self)
10451045

1046-
v = a[2]
1046+
v = a[2] as AnyObject
10471047
expectEqual(30, (v as! TestObjCValueTy).value)
10481048
let idValue2 = unsafeBitCast(v, to: UInt.self)
10491049

@@ -1059,9 +1059,9 @@ ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Reallocate") {
10591059

10601060
// Check that mutating the native array did not affect the bridged array.
10611061
expectEqual(3, a.count)
1062-
expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self))
1063-
expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self))
1064-
expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self))
1062+
expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self))
1063+
expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self))
1064+
expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self))
10651065

10661066
expectAutoreleasedKeysAndValues(unopt: (0, 3))
10671067
}

0 commit comments

Comments
 (0)