Update validation tests for id-as-Any.

This commit is contained in:
Joe Groff
2016-07-24 20:16:47 -07:00
parent 5bfd6cc0c7
commit 21c15d8fe9
13 changed files with 114 additions and 111 deletions

View File

@@ -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..<returnedCount {
let key: AnyObject = state.itemsPtr![i]!
let value: AnyObject = d.object(forKey: key)!
let value: AnyObject = d.object(forKey: key)! as AnyObject
let kv = (key, value)
sink(kv)
itemsReturned += 1
@@ -611,7 +611,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
slurpFastEnumerationFromSwift(
a, enumerator, sink, maxItems: maxFastEnumerationItems)
while let value = enumerator.nextObject() {
sink(value)
sink(value as AnyObject)
}
}
@@ -623,8 +623,8 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
slurpFastEnumerationFromSwift(
d, enumerator, sink, maxItems: maxFastEnumerationItems)
while let key = enumerator.nextObject() {
let value: AnyObject = d.object(forKey: key)!
let kv = (key, value)
let value: AnyObject = d.object(forKey: key)! as AnyObject
let kv = (key as AnyObject, value)
sink(kv)
}
}
@@ -635,7 +635,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
let objcValues = NSMutableArray()
slurpFastEnumerationOfArrayFromObjCImpl(a, fe, objcValues)
for value in objcValues {
sink(value)
sink(value as AnyObject)
}
}
@@ -759,7 +759,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
let objcValues = NSMutableArray()
slurpFastEnumerationOfArrayFromObjCImpl(s, fe, objcValues)
for value in objcValues {
sink(value)
sink(value as AnyObject)
}
}
@@ -770,7 +770,7 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
slurpFastEnumerationFromSwift(
s, enumerator, sink, maxItems: maxFastEnumerationItems)
while let value = enumerator.nextObject() {
sink(value)
sink(value as AnyObject)
}
}
@@ -862,8 +862,8 @@ typealias AnyObjectTuple2 = (AnyObject, AnyObject)
let objcPairs = NSMutableArray()
slurpFastEnumerationOfDictionaryFromObjCImpl(d, fe, objcPairs)
for i in 0..<objcPairs.count/2 {
let key: AnyObject = objcPairs[i * 2]
let value: AnyObject = objcPairs[i * 2 + 1]
let key = objcPairs[i * 2] as AnyObject
let value = objcPairs[i * 2 + 1] as AnyObject
let kv = (key, value)
sink(kv)
}

View File

@@ -16,7 +16,7 @@ FoundationExtrasTests.test("withOverriddenLocaleCurrentLocale(Locale)") {
// these locales happens to be the same as the actual current locale.
do {
let result = withOverriddenLocaleCurrentLocale(
Locale(identifier: "en_US")) {
Locale(identifier: "en_US") as NSLocale) {
() -> 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 ()

View File

@@ -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)
}
}

View File

@@ -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(

View File

@@ -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))
}

View File

@@ -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()

View File

@@ -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<NSObject, AnyObject> = d
var dOO = d as Dictionary<NSObject, AnyObject>
assert(dOO.count == 3)
var v: AnyObject? = dOO[TestObjCKeyTy(10)]
@@ -3069,7 +3070,7 @@ DictionaryTestSuite.test("DictionaryUpcastBridged") {
}
do {
var dOV: Dictionary<NSObject, TestBridgedValueTy> = d
var dOV = d as Dictionary<NSObject, TestBridgedValueTy>
assert(dOV.count == 3)
var v = dOV[TestObjCKeyTy(10)]
@@ -3083,7 +3084,7 @@ DictionaryTestSuite.test("DictionaryUpcastBridged") {
}
do {
var dVO: Dictionary<TestBridgedKeyTy, AnyObject> = d
var dVO = d as Dictionary<TestBridgedKeyTy, AnyObject>
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()
}

View File

@@ -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(

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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<NSObject> = s
var s = s as Set<NSObject>
expectEqual(3, s.count)
expectTrue(s.contains(TestBridgedKeyTy(1010) as NSObject))
@@ -2498,7 +2498,7 @@ SetTestSuite.test("SetUpcastBridged") {
}
do {
var s: Set<TestObjCKeyTy> = s
var s = s as Set<TestObjCKeyTy>
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
}

View File

@@ -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

View File

@@ -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