diff --git a/test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift b/test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift index 637ce6dfa96..1629e629612 100644 --- a/test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift +++ b/test/1_stdlib/Inputs/DictionaryKeyValueTypesObjC.swift @@ -84,7 +84,7 @@ class TestObjCKeyTy : NSObject, NSCopying { } @objc(copyWithZone:) - func copy(with zone: NSZone?) -> AnyObject { + func copy(with zone: NSZone?) -> Any { return TestObjCKeyTy(value) } @@ -93,7 +93,7 @@ class TestObjCKeyTy : NSObject, NSCopying { return value.description } - override func isEqual(_ object: AnyObject!) -> Bool { + override func isEqual(_ object: Any!) -> Bool { if let other = object { if let otherObjcKey = other as? TestObjCKeyTy { return self.value == otherObjcKey.value @@ -136,7 +136,7 @@ class TestObjCInvalidKeyTy { } @objc - func isEqual(_ object: AnyObject!) -> Bool { + func isEqual(_ object: Any!) -> Bool { fatalError() } @@ -207,7 +207,7 @@ class TestObjCEquatableValueTy : NSObject { serial = -serial } - override func isEqual(_ object: AnyObject!) -> Bool { + override func isEqual(_ object: Any!) -> Bool { if let other = object { if let otherObjcKey = other as? TestObjCEquatableValueTy { return self.value == otherObjcKey.value @@ -586,7 +586,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject) } for i in 0.. Int in expectEqual("en_US", Locale.current.identifier) return 42 @@ -25,7 +25,7 @@ FoundationExtrasTests.test("withOverriddenLocaleCurrentLocale(Locale)") { } do { let result = withOverriddenLocaleCurrentLocale( - Locale(identifier: "uk")) { + Locale(identifier: "uk") as NSLocale) { () -> Int in expectEqual("uk", Locale.current.identifier) return 42 @@ -36,13 +36,13 @@ FoundationExtrasTests.test("withOverriddenLocaleCurrentLocale(Locale)") { FoundationExtrasTests.test("withOverriddenLocaleCurrentLocale(Locale)/nested") { withOverriddenLocaleCurrentLocale( - Locale(identifier: "uk")) { + Locale(identifier: "uk") as NSLocale) { () -> Void in expectCrashLater() withOverriddenLocaleCurrentLocale( - Locale(identifier: "uk")) { + Locale(identifier: "uk") as NSLocale) { () -> Void in return () diff --git a/validation-test/compiler_crashers_fixed/00324-swift-shortcircuit-isequal.swift b/validation-test/compiler_crashers_fixed/00324-swift-shortcircuit-isequal.swift index a946c3f4aac..346d94d37a3 100644 --- a/validation-test/compiler_crashers_fixed/00324-swift-shortcircuit-isequal.swift +++ b/validation-test/compiler_crashers_fixed/00324-swift-shortcircuit-isequal.swift @@ -15,7 +15,7 @@ import Foundation class Test: NSObject { - override func isEqual(_ object: AnyObject?) -> Bool { + override func isEqual(_ object: Any?) -> Bool { return false && super.isEqual(object) } } diff --git a/validation-test/stdlib/ArrayBridging.swift b/validation-test/stdlib/ArrayBridging.swift index 68b06ed8926..626fe4cb796 100644 --- a/validation-test/stdlib/ArrayBridging.swift +++ b/validation-test/stdlib/ArrayBridging.swift @@ -39,7 +39,7 @@ struct ArrayBridge_objectAtIndex_RaceTest : RaceTestWithPerTrialData { _ raceData: RaceData, _ threadLocalData: inout ThreadLocalData ) -> Observation { let nsa = raceData.nsa - let v: AnyObject = nsa.object(at: 0) + let v = nsa.object(at: 0) as AnyObject return Observation(unsafeBitCast(v, to: UInt.self)) } @@ -79,10 +79,10 @@ struct ArrayBridge_FastEnumeration_ObjC_RaceTest : let objcValues = NSMutableArray() slurpFastEnumerationOfArrayFromObjCImpl(nsa, nsa, objcValues) return Observation( - unsafeBitCast(objcValues[0], to: UInt.self), - unsafeBitCast(objcValues[1], to: UInt.self), - unsafeBitCast(objcValues[2], to: UInt.self), - unsafeBitCast(objcValues[3], to: UInt.self)) + unsafeBitCast(objcValues[0] as AnyObject, to: UInt.self), + unsafeBitCast(objcValues[1] as AnyObject, to: UInt.self), + unsafeBitCast(objcValues[2] as AnyObject, to: UInt.self), + unsafeBitCast(objcValues[3] as AnyObject, to: UInt.self)) } func evaluateObservations( diff --git a/validation-test/stdlib/ArrayNew.swift.gyb b/validation-test/stdlib/ArrayNew.swift.gyb index 9a17b0c8c57..d212c3f2d08 100644 --- a/validation-test/stdlib/ArrayNew.swift.gyb +++ b/validation-test/stdlib/ArrayNew.swift.gyb @@ -291,13 +291,13 @@ class CustomImmutableNSArray : NSArray { } @objc(copyWithZone:) - override func copy(with zone: NSZone?) -> AnyObject { + override func copy(with zone: NSZone?) -> Any { CustomImmutableNSArray.timesCopyWithZoneWasCalled += 1 return self } @objc - override func object(at index: Int) -> AnyObject { + override func object(at index: Int) -> Any { CustomImmutableNSArray.timesObjectAtIndexWasCalled += 1 return _data[index] } @@ -535,22 +535,22 @@ for index in [ -100, -1, 3, 4, 100 ] { ArrayTestSuite.test("BridgedToObjC/Verbatim/objectAtIndex") { let a = getBridgedNSArrayOfRefTypeVerbatimBridged(numElements: 3) - var v: AnyObject = a.object(at: 0) + var v: AnyObject = a.object(at: 0) as AnyObject expectEqual(10, (v as! TestObjCValueTy).value) let idValue0 = unsafeBitCast(v, to: UInt.self) - v = a.object(at: 1) + v = a.object(at: 1) as AnyObject expectEqual(20, (v as! TestObjCValueTy).value) let idValue1 = unsafeBitCast(v, to: UInt.self) - v = a.object(at: 2) + v = a.object(at: 2) as AnyObject expectEqual(30, (v as! TestObjCValueTy).value) let idValue2 = unsafeBitCast(v, to: UInt.self) for i in 0..<3 { - expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self)) - expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self)) - expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self)) + expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self)) + expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self)) + expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self)) } expectAutoreleasedKeysAndValues(unopt: (0, 3)) @@ -608,9 +608,9 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/getObjects") { let idValue2 = unsafeBitCast(v, to: UInt.self) for i in 0..<3 { - expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self)) - expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self)) - expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self)) + expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self)) + expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self)) + expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self)) } buffer.deallocate(capacity: 3) @@ -621,7 +621,7 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/getObjects") { ArrayTestSuite.test("BridgedToObjC/Verbatim/copyWithZone") { let a = getBridgedNSArrayOfRefTypeVerbatimBridged(numElements: 3) - let copy: AnyObject = a.copy(with: nil) + let copy: AnyObject = a.copy(with: nil) as AnyObject expectEqual( unsafeBitCast(a, to: UInt.self), unsafeBitCast(copy, to: UInt.self)) } @@ -707,15 +707,15 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/ObjectEnumerator/FastEnumeration/Use ArrayTestSuite.test("BridgedToObjC/Verbatim/BridgeBack/Reallocate") { let a = getBridgedNSArrayOfRefTypeVerbatimBridged(numElements: 3) - var v: AnyObject = a[0] + var v: AnyObject = a[0] as AnyObject expectEqual(10, (v as! TestObjCValueTy).value) let idValue0 = unsafeBitCast(v, to: UInt.self) - v = a[1] + v = a[1] as AnyObject expectEqual(20, (v as! TestObjCValueTy).value) let idValue1 = unsafeBitCast(v, to: UInt.self) - v = a[2] + v = a[2] as AnyObject expectEqual(30, (v as! TestObjCValueTy).value) let idValue2 = unsafeBitCast(v, to: UInt.self) @@ -731,9 +731,9 @@ ArrayTestSuite.test("BridgedToObjC/Verbatim/BridgeBack/Reallocate") { // Check that mutating the native array did not affect the bridged array. expectEqual(3, a.count) - expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self)) - expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self)) - expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self)) + expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self)) + expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self)) + expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self)) expectAutoreleasedKeysAndValues(unopt: (0, 3)) } @@ -808,22 +808,22 @@ for index in [ -100, -1, 3, 4, 100 ] { ArrayTestSuite.test("BridgedToObjC/Custom/objectAtIndex") { let a = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3) - var v: AnyObject = a.object(at: 0) + var v: AnyObject = a.object(at: 0) as AnyObject expectEqual(10, (v as! TestObjCValueTy).value) let idValue0 = unsafeBitCast(v, to: UInt.self) - v = a.object(at: 1) + v = a.object(at: 1) as AnyObject expectEqual(20, (v as! TestObjCValueTy).value) let idValue1 = unsafeBitCast(v, to: UInt.self) - v = a.object(at: 2) + v = a.object(at: 2) as AnyObject expectEqual(30, (v as! TestObjCValueTy).value) let idValue2 = unsafeBitCast(v, to: UInt.self) for i in 0..<3 { - expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self)) - expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self)) - expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self)) + expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self)) + expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self)) + expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self)) } expectEqual(3, TestBridgedValueTy.bridgeOperations) @@ -882,9 +882,9 @@ ArrayTestSuite.test("BridgedToObjC/Custom/getObjects") { let idValue2 = unsafeBitCast(v, to: UInt.self) for i in 0..<3 { - expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self)) - expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self)) - expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self)) + expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self)) + expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self)) + expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self)) } buffer.deallocate(capacity: 3) @@ -896,7 +896,7 @@ ArrayTestSuite.test("BridgedToObjC/Custom/getObjects") { ArrayTestSuite.test("BridgedToObjC/Custom/copyWithZone") { let a = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3) - let copy: AnyObject = a.copy(with: nil) + let copy: AnyObject = a.copy(with: nil) as AnyObject expectEqual( unsafeBitCast(a, to: UInt.self), unsafeBitCast(copy, to: UInt.self)) @@ -1001,15 +1001,15 @@ ArrayTestSuite.test("BridgedToObjC/Custom/ObjectEnumerator/FastEnumeration/UseFr ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Cast") { let a = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3) - var v: AnyObject = a[0] + var v: AnyObject = a[0] as AnyObject expectEqual(10, (v as! TestObjCValueTy).value) let idValue0 = unsafeBitCast(v, to: UInt.self) - v = a[1] + v = a[1] as AnyObject expectEqual(20, (v as! TestObjCValueTy).value) let idValue1 = unsafeBitCast(v, to: UInt.self) - v = a[2] + v = a[2] as AnyObject expectEqual(30, (v as! TestObjCValueTy).value) let idValue2 = unsafeBitCast(v, to: UInt.self) @@ -1025,9 +1025,9 @@ ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Cast") { // Check that mutating the native array did not affect the bridged array. expectEqual(3, a.count) - expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self)) - expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self)) - expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self)) + expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self)) + expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self)) + expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self)) expectAutoreleasedKeysAndValues(unopt: (0, 3)) } @@ -1035,15 +1035,15 @@ ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Cast") { ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Reallocate") { let a = getBridgedNSArrayOfValueTypeCustomBridged(numElements: 3) - var v: AnyObject = a[0] + var v: AnyObject = a[0] as AnyObject expectEqual(10, (v as! TestObjCValueTy).value) let idValue0 = unsafeBitCast(v, to: UInt.self) - v = a[1] + v = a[1] as AnyObject expectEqual(20, (v as! TestObjCValueTy).value) let idValue1 = unsafeBitCast(v, to: UInt.self) - v = a[2] + v = a[2] as AnyObject expectEqual(30, (v as! TestObjCValueTy).value) let idValue2 = unsafeBitCast(v, to: UInt.self) @@ -1059,9 +1059,9 @@ ArrayTestSuite.test("BridgedToObjC/Custom/BridgeBack/Reallocate") { // Check that mutating the native array did not affect the bridged array. expectEqual(3, a.count) - expectEqual(idValue0, unsafeBitCast(a.object(at: 0), to: UInt.self)) - expectEqual(idValue1, unsafeBitCast(a.object(at: 1), to: UInt.self)) - expectEqual(idValue2, unsafeBitCast(a.object(at: 2), to: UInt.self)) + expectEqual(idValue0, unsafeBitCast(a.object(at: 0) as AnyObject, to: UInt.self)) + expectEqual(idValue1, unsafeBitCast(a.object(at: 1) as AnyObject, to: UInt.self)) + expectEqual(idValue2, unsafeBitCast(a.object(at: 2) as AnyObject, to: UInt.self)) expectAutoreleasedKeysAndValues(unopt: (0, 3)) } diff --git a/validation-test/stdlib/CoreData.swift b/validation-test/stdlib/CoreData.swift index f2ed02b7289..67457220d0e 100644 --- a/validation-test/stdlib/CoreData.swift +++ b/validation-test/stdlib/CoreData.swift @@ -23,8 +23,8 @@ CoreDataTests.test("downcasting") { let casted = dictionaries as? [[NSObject: AnyObject]] expectNotEmpty(casted) - expectEqual([[:], [:]], casted!) - expectEqual([[:], [:]], dictionaries as! [[NSObject: AnyObject]]) + expectEqual([[:], [:]] as NSArray, casted! as NSArray) + expectEqual([[:], [:]] as NSArray, dictionaries as! [[NSObject: AnyObject]] as NSArray) } CoreDataTests.test("bridging") { @@ -34,8 +34,8 @@ CoreDataTests.test("bridging") { let casted = dictionaries as? [[NSObject: AnyObject]] expectNotEmpty(casted) - expectEqual([[:], [:]], casted!) - expectEqual([[:], [:]], dictionaries as! [[NSObject: AnyObject]]) + expectEqual([[:], [:]] as NSArray, casted! as NSArray) + expectEqual([[:], [:]] as NSArray, dictionaries as! [[NSObject: AnyObject]] as NSArray) } runAllTests() diff --git a/validation-test/stdlib/Dictionary.swift b/validation-test/stdlib/Dictionary.swift index c806dda0f6f..90e75785d9f 100644 --- a/validation-test/stdlib/Dictionary.swift +++ b/validation-test/stdlib/Dictionary.swift @@ -1283,7 +1283,7 @@ class ParallelArrayDictionary : NSDictionary { } @objc(copyWithZone:) - override func copy(with zone: NSZone?) -> AnyObject { + override func copy(with zone: NSZone?) -> Any { // Ensure that copying this dictionary does not produce a CoreFoundation // object. return self @@ -1305,7 +1305,7 @@ class ParallelArrayDictionary : NSDictionary { return 0 } - override func object(forKey aKey: AnyObject) -> AnyObject? { + override func object(forKey aKey: Any) -> Any? { return value } @@ -1348,12 +1348,12 @@ class CustomImmutableNSDictionary : NSDictionary { } @objc(copyWithZone:) - override func copy(with zone: NSZone?) -> AnyObject { + override func copy(with zone: NSZone?) -> Any { CustomImmutableNSDictionary.timesCopyWithZoneWasCalled += 1 return self } - override func object(forKey aKey: AnyObject) -> AnyObject? { + override func object(forKey aKey: Any) -> Any? { CustomImmutableNSDictionary.timesObjectForKeyWasCalled += 1 return getAsNSDictionary([10: 1010, 20: 1020, 30: 1030]).object(forKey: aKey) } @@ -2570,15 +2570,15 @@ DictionaryTestSuite.test("BridgedToObjC.Verbatim.Count") { DictionaryTestSuite.test("BridgedToObjC.Verbatim.ObjectForKey") { let d = getBridgedNSDictionaryOfRefTypesBridgedVerbatim() - var v: AnyObject? = d.object(forKey: TestObjCKeyTy(10)) + var v: AnyObject? = d.object(forKey: TestObjCKeyTy(10)).map { $0 as AnyObject } expectEqual(1010, (v as! TestObjCValueTy).value) let idValue10 = unsafeBitCast(v, to: UInt.self) - v = d.object(forKey: TestObjCKeyTy(20)) + v = d.object(forKey: TestObjCKeyTy(20)).map { $0 as AnyObject } expectEqual(1020, (v as! TestObjCValueTy).value) let idValue20 = unsafeBitCast(v, to: UInt.self) - v = d.object(forKey: TestObjCKeyTy(30)) + v = d.object(forKey: TestObjCKeyTy(30)).map { $0 as AnyObject } expectEqual(1030, (v as! TestObjCValueTy).value) let idValue30 = unsafeBitCast(v, to: UInt.self) @@ -2591,13 +2591,13 @@ DictionaryTestSuite.test("BridgedToObjC.Verbatim.ObjectForKey") { for i in 0..<3 { expectEqual(idValue10, unsafeBitCast( - d.object(forKey: TestObjCKeyTy(10)), to: UInt.self)) + d.object(forKey: TestObjCKeyTy(10)).map { $0 as AnyObject }, to: UInt.self)) expectEqual(idValue20, unsafeBitCast( - d.object(forKey: TestObjCKeyTy(20)), to: UInt.self)) + d.object(forKey: TestObjCKeyTy(20)).map { $0 as AnyObject }, to: UInt.self)) expectEqual(idValue30, unsafeBitCast( - d.object(forKey: TestObjCKeyTy(30)), to: UInt.self)) + d.object(forKey: TestObjCKeyTy(30)).map { $0 as AnyObject }, to: UInt.self)) } expectAutoreleasedKeysAndValues(unopt: (0, 3)) @@ -2614,14 +2614,15 @@ DictionaryTestSuite.test("BridgedToObjC.Verbatim.KeyEnumerator.NextObject") { var dataPairs = Array<(Int, Int)>() var identityPairs = Array<(UInt, UInt)>() while let key = enumerator.nextObject() { - let value: AnyObject = d.object(forKey: key)! + let keyObj = key as AnyObject + let value: AnyObject = d.object(forKey: keyObj)! as AnyObject let dataPair = - ((key as! TestObjCKeyTy).value, (value as! TestObjCValueTy).value) + ((keyObj as! TestObjCKeyTy).value, (value as! TestObjCValueTy).value) dataPairs.append(dataPair) let identityPair = - (unsafeBitCast(key, to: UInt.self), + (unsafeBitCast(keyObj, to: UInt.self), unsafeBitCast(value, to: UInt.self)) identityPairs.append(identityPair) } @@ -2739,7 +2740,7 @@ DictionaryTestSuite.test("BridgedToObjC.KeyValue_ValueTypesCustomBridged") { var pairs = Array<(Int, Int)>() while let key = enumerator.nextObject() { - let value: AnyObject = d.object(forKey: key)! + let value: AnyObject = d.object(forKey: key)! as AnyObject let kv = ((key as! TestObjCKeyTy).value, (value as! TestObjCValueTy).value) pairs.append(kv) } @@ -2846,7 +2847,7 @@ DictionaryTestSuite.test("BridgedToObjC.Key_ValueTypeCustomBridged") { var pairs = Array<(Int, Int)>() while let key = enumerator.nextObject() { - let value: AnyObject = d.object(forKey: key)! + let value: AnyObject = d.object(forKey: key)! as AnyObject let kv = ((key as! TestObjCKeyTy).value, (value as! TestObjCValueTy).value) pairs.append(kv) } @@ -2876,7 +2877,7 @@ DictionaryTestSuite.test("BridgedToObjC.Value_ValueTypeCustomBridged") { var pairs = Array<(Int, Int)>() while let key = enumerator.nextObject() { - let value: AnyObject = d.object(forKey: key)! + let value: AnyObject = d.object(forKey: key)! as AnyObject let kv = ((key as! TestObjCKeyTy).value, (value as! TestObjCValueTy).value) pairs.append(kv) } @@ -2912,7 +2913,7 @@ DictionaryTestSuite.test("BridgingRoundtrip") { var pairs = Array<(key: Int, value: Int)>() while let key = enumerator.nextObject() { - let value: AnyObject = d.object(forKey: key)! + let value: AnyObject = d.object(forKey: key)! as AnyObject let kv = ((key as! TestObjCKeyTy).value, (value as! TestObjCValueTy).value) pairs.append(kv) } @@ -3055,7 +3056,7 @@ DictionaryTestSuite.test("DictionaryUpcastBridged") { d[TestBridgedKeyTy(30)] = TestBridgedValueTy(1030) do { - var dOO: Dictionary = d + var dOO = d as Dictionary assert(dOO.count == 3) var v: AnyObject? = dOO[TestObjCKeyTy(10)] @@ -3069,7 +3070,7 @@ DictionaryTestSuite.test("DictionaryUpcastBridged") { } do { - var dOV: Dictionary = d + var dOV = d as Dictionary assert(dOV.count == 3) var v = dOV[TestObjCKeyTy(10)] @@ -3083,7 +3084,7 @@ DictionaryTestSuite.test("DictionaryUpcastBridged") { } do { - var dVO: Dictionary = d + var dVO = d as Dictionary assert(dVO.count == 3) var v: AnyObject? = dVO[TestBridgedKeyTy(10)] @@ -3490,13 +3491,13 @@ class MockDictionaryWithCustomCount : NSDictionary { } @objc(copyWithZone:) - override func copy(with zone: NSZone?) -> AnyObject { + override func copy(with zone: NSZone?) -> Any { // Ensure that copying this dictionary produces an object of the same // dynamic type. return self } - override func object(forKey aKey: AnyObject) -> AnyObject? { + override func object(forKey aKey: Any) -> Any? { expectUnreachable() return NSObject() } diff --git a/validation-test/stdlib/DictionaryBridging.swift b/validation-test/stdlib/DictionaryBridging.swift index f01e2a8be8b..5ca3e25c711 100644 --- a/validation-test/stdlib/DictionaryBridging.swift +++ b/validation-test/stdlib/DictionaryBridging.swift @@ -41,7 +41,7 @@ struct DictionaryBridge_objectForKey_RaceTest : RaceTestWithPerTrialData { _ raceData: RaceData, _ threadLocalData: inout ThreadLocalData ) -> Observation { let nsd = raceData.nsd - let v: AnyObject? = nsd.object(forKey: key) + let v: AnyObject? = nsd.object(forKey: key).map { $0 as AnyObject } return Observation(unsafeBitCast(v, to: UInt.self)) } @@ -82,10 +82,10 @@ struct DictionaryBridge_KeyEnumerator_FastEnumeration_ObjC_RaceTest : let objcPairs = NSMutableArray() slurpFastEnumerationOfDictionaryFromObjCImpl(nsd, nsd, objcPairs) return Observation( - unsafeBitCast(objcPairs[0], to: UInt.self), - unsafeBitCast(objcPairs[1], to: UInt.self), - unsafeBitCast(objcPairs[2], to: UInt.self), - unsafeBitCast(objcPairs[3], to: UInt.self)) + unsafeBitCast(objcPairs[0] as AnyObject, to: UInt.self), + unsafeBitCast(objcPairs[1] as AnyObject, to: UInt.self), + unsafeBitCast(objcPairs[2] as AnyObject, to: UInt.self), + unsafeBitCast(objcPairs[3] as AnyObject, to: UInt.self)) } func evaluateObservations( diff --git a/validation-test/stdlib/ErrorProtocol.swift b/validation-test/stdlib/ErrorProtocol.swift index 310d9f2b29b..886ee44c7a1 100644 --- a/validation-test/stdlib/ErrorProtocol.swift +++ b/validation-test/stdlib/ErrorProtocol.swift @@ -31,9 +31,11 @@ struct ErrorAsNSErrorRaceTest : RaceTestWithPerTrialData { let ns = raceData.error as NSError // Use valueForKey to bypass bridging, so we can verify that the identity // of the unbridged NSString object is stable. - let domainInt: Int = unsafeBitCast(ns.value(forKey: "domain"), to: Int.self) + let domainInt: Int = unsafeBitCast(ns.value(forKey: "domain").map { $0 as AnyObject }, + to: Int.self) let code: Int = ns.code - let userInfoInt: Int = unsafeBitCast(ns.value(forKey: "userInfo"), to: Int.self) + let userInfoInt: Int = unsafeBitCast(ns.value(forKey: "userInfo").map { $0 as AnyObject }, + to: Int.self) return Observation3Int(domainInt, code, userInfoInt) } diff --git a/validation-test/stdlib/ObjectiveC.swift b/validation-test/stdlib/ObjectiveC.swift index 12341e65345..a11f367162f 100644 --- a/validation-test/stdlib/ObjectiveC.swift +++ b/validation-test/stdlib/ObjectiveC.swift @@ -15,7 +15,7 @@ class NSObjectWithCustomHashable : NSObject { self._hashValue = hashValue } - override func isEqual(_ other: AnyObject?) -> Bool { + override func isEqual(_ other: Any?) -> Bool { let other_ = other as! NSObjectWithCustomHashable return self._value == other_._value } diff --git a/validation-test/stdlib/Set.swift b/validation-test/stdlib/Set.swift index d5aed222709..33011cb9912 100644 --- a/validation-test/stdlib/Set.swift +++ b/validation-test/stdlib/Set.swift @@ -1204,12 +1204,12 @@ class CustomImmutableNSSet : NSSet { } @objc(copyWithZone:) - override func copy(with zone: NSZone?) -> AnyObject { + override func copy(with zone: NSZone?) -> Any { CustomImmutableNSSet.timesCopyWithZoneWasCalled += 1 return self } - override func member(_ object: AnyObject) -> AnyObject? { + override func member(_ object: Any) -> Any? { CustomImmutableNSSet.timesMemberWasCalled += 1 return getAsNSSet([ 1010, 1020, 1030 ]).member(object) } @@ -2170,15 +2170,15 @@ SetTestSuite.test("BridgedToObjC.Verbatim.Count") { SetTestSuite.test("BridgedToObjC.Verbatim.Contains") { let s = getBridgedNSSetOfRefTypesBridgedVerbatim() - var v: AnyObject? = s.member(TestObjCKeyTy(1010)) + var v: AnyObject? = s.member(TestObjCKeyTy(1010)).map { $0 as AnyObject } expectEqual(1010, (v as! TestObjCKeyTy).value) let idValue10 = unsafeBitCast(v, to: UInt.self) - v = s.member(TestObjCKeyTy(2020)) + v = s.member(TestObjCKeyTy(2020)).map { $0 as AnyObject } expectEqual(2020, (v as! TestObjCKeyTy).value) let idValue20 = unsafeBitCast(v, to: UInt.self) - v = s.member(TestObjCKeyTy(3030)) + v = s.member(TestObjCKeyTy(3030)).map { $0 as AnyObject } expectEqual(3030, (v as! TestObjCKeyTy).value) let idValue30 = unsafeBitCast(v, to: UInt.self) @@ -2191,13 +2191,13 @@ SetTestSuite.test("BridgedToObjC.Verbatim.Contains") { for i in 0..<3 { expectEqual(idValue10, - unsafeBitCast(s.member(TestObjCKeyTy(1010)), to: UInt.self)) + unsafeBitCast(s.member(TestObjCKeyTy(1010)).map { $0 as AnyObject }, to: UInt.self)) expectEqual(idValue20, - unsafeBitCast(s.member(TestObjCKeyTy(2020)), to: UInt.self)) + unsafeBitCast(s.member(TestObjCKeyTy(2020)).map { $0 as AnyObject }, to: UInt.self)) expectEqual(idValue30, - unsafeBitCast(s.member(TestObjCKeyTy(3030)), to: UInt.self)) + unsafeBitCast(s.member(TestObjCKeyTy(3030)).map { $0 as AnyObject }, to: UInt.self)) } expectAutoreleasedKeysAndValues(unopt: (3, 0)) @@ -2489,7 +2489,7 @@ SetTestSuite.test("SetUpcastBridged") { } do { - var s: Set = s + var s = s as Set expectEqual(3, s.count) expectTrue(s.contains(TestBridgedKeyTy(1010) as NSObject)) @@ -2498,7 +2498,7 @@ SetTestSuite.test("SetUpcastBridged") { } do { - var s: Set = s + var s = s as Set expectEqual(3, s.count) expectTrue(s.contains(TestBridgedKeyTy(1010) as TestObjCKeyTy)) @@ -3526,13 +3526,13 @@ class MockSetWithCustomCount : NSSet { } @objc(copyWithZone:) - override func copy(with zone: NSZone?) -> AnyObject { + override func copy(with zone: NSZone?) -> Any { // Ensure that copying this set produces an object of the same // dynamic type. return self } - override func member(_ object: AnyObject) -> AnyObject? { + override func member(_ object: Any) -> Any? { expectUnreachable() return object } diff --git a/validation-test/stdlib/Unicode.swift.gyb b/validation-test/stdlib/Unicode.swift.gyb index 1dd9b118c32..540c2736044 100644 --- a/validation-test/stdlib/Unicode.swift.gyb +++ b/validation-test/stdlib/Unicode.swift.gyb @@ -2127,7 +2127,7 @@ class NonContiguousNSString : NSString { } @objc(copyWithZone:) - override func copy(with zone: NSZone?) -> AnyObject { + override func copy(with zone: NSZone?) -> Any { // Ensure that copying this string produces a class that CoreFoundation // does not know about. return self diff --git a/validation-test/stdlib/UnicodeTrie.swift.gyb b/validation-test/stdlib/UnicodeTrie.swift.gyb index e2cef04f8d6..0010f040faf 100644 --- a/validation-test/stdlib/UnicodeTrie.swift.gyb +++ b/validation-test/stdlib/UnicodeTrie.swift.gyb @@ -107,7 +107,7 @@ class NonContiguousNSString : NSString { } @objc(copyWithZone:) - override func copy(with zone: NSZone?) -> AnyObject { + override func copy(with zone: NSZone?) -> Any { // Ensure that copying this string produces a class that CoreFoundation // does not know about. return self