Skip to content

Commit 6cda1f3

Browse files
rudkxphausler
authored andcommitted
Use an argument label to disambiguate calls to _SwiftValue.fetch. (#753)
Back out the changes from d9cdc7e and 1576958, and instead use an argument label to disambiguate calls to `fetch`.
1 parent 587557d commit 6cda1f3

11 files changed

+31
-31
lines changed

Foundation/Bridging.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ internal final class _SwiftValue : NSObject, NSCopying {
7777

7878
static func fetch(_ object: AnyObject?) -> Any? {
7979
if let obj = object {
80-
return fetch(obj)
80+
return fetch(nonOptional: obj)
8181
}
8282
return nil
8383
}
8484

85-
static func fetch(_ object: AnyObject) -> Any {
85+
static func fetch(nonOptional object: AnyObject) -> Any {
8686
if let container = object as? _SwiftValue {
8787
return container.value
8888
} else if let val = object as? _StructBridgeable {

Foundation/Dictionary.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ extension Dictionary : _ObjectTypeBridgeable {
6565
CFDictionaryGetKeysAndValues(cf, keys, values)
6666

6767
for idx in 0..<cnt {
68-
let key = _SwiftValue.fetch(unsafeBitCast(keys.advanced(by: idx).pointee!, to: AnyObject.self))
69-
let value = _SwiftValue.fetch(unsafeBitCast(values.advanced(by: idx).pointee!, to: AnyObject.self))
68+
let key = _SwiftValue.fetch(nonOptional: unsafeBitCast(keys.advanced(by: idx).pointee!, to: AnyObject.self))
69+
let value = _SwiftValue.fetch(nonOptional: unsafeBitCast(values.advanced(by: idx).pointee!, to: AnyObject.self))
7070
guard let k = key as? Key, let v = value as? Value else {
7171
failedConversion = true
7272
break

Foundation/NSArray.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
2424
guard type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self else {
2525
NSRequiresConcreteImplementation()
2626
}
27-
return _SwiftValue.fetch(_storage[index])
27+
return _SwiftValue.fetch(nonOptional: _storage[index])
2828
}
2929

3030
public convenience override init() {
@@ -151,7 +151,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
151151

152152
internal var allObjects: [Any] {
153153
if type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self {
154-
return _storage.map { _SwiftValue.fetch($0) }
154+
return _storage.map { _SwiftValue.fetch(nonOptional: $0) }
155155
} else {
156156
return (0..<count).map { idx in
157157
return self[idx]
@@ -226,7 +226,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
226226
for idx in 0..<count {
227227
let item = _SwiftValue.store(self[idx])
228228
if set.contains(item) {
229-
return _SwiftValue.fetch(item)
229+
return _SwiftValue.fetch(nonOptional: item)
230230
}
231231
}
232232
return nil
@@ -236,7 +236,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
236236
objects.reserveCapacity(objects.count + range.length)
237237

238238
if type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self {
239-
objects += _storage[range.toRange()!].map { _SwiftValue.fetch($0) }
239+
objects += _storage[range.toRange()!].map { _SwiftValue.fetch(nonOptional: $0) }
240240
return
241241
}
242242

Foundation/NSCFArray.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ internal final class _NSCFArray : NSMutableArray {
3434

3535
override func object(at index: Int) -> Any {
3636
let value = CFArrayGetValueAtIndex(_cfObject, index)
37-
return _SwiftValue.fetch(unsafeBitCast(value, to: AnyObject.self))
37+
return _SwiftValue.fetch(nonOptional: unsafeBitCast(value, to: AnyObject.self))
3838
}
3939

4040
override func insert(_ value: Any, at index: Int) {

Foundation/NSCFDictionary.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal final class _NSCFDictionary : NSMutableDictionary {
3939
override func object(forKey aKey: Any) -> Any? {
4040
let value = CFDictionaryGetValue(_cfObject, unsafeBitCast(_SwiftValue.store(aKey), to: UnsafeRawPointer.self))
4141
if value != nil {
42-
return _SwiftValue.fetch(unsafeBitCast(value, to: AnyObject.self) as AnyObject?)
42+
return _SwiftValue.fetch(nonOptional: unsafeBitCast(value, to: AnyObject.self))
4343
} else {
4444
return nil
4545
}
@@ -117,7 +117,7 @@ internal func _CFSwiftDictionaryGetValue(_ dictionary: AnyObject, key: AnyObject
117117
return Unmanaged<AnyObject>.passUnretained(obj)
118118
}
119119
} else {
120-
let k = _SwiftValue.fetch(key)
120+
let k = _SwiftValue.fetch(nonOptional: key)
121121
let value = dict.object(forKey: k)
122122
let v = _SwiftValue.store(value)
123123
dict._storage[key as! NSObject] = v

Foundation/NSCFSet.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ internal final class _NSCFSet : NSMutableSet {
4141
guard let value = CFSetGetValue(_cfObject, unsafeBitCast(_SwiftValue.store(object), to: UnsafeRawPointer.self)) else {
4242
return nil
4343
}
44-
return _SwiftValue.fetch(unsafeBitCast(value, to: AnyObject.self) as AnyObject?)
44+
return _SwiftValue.fetch(nonOptional: unsafeBitCast(value, to: AnyObject.self))
4545

4646
}
4747

Foundation/NSDictionary.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
2727
NSRequiresConcreteImplementation()
2828
}
2929
if let val = _storage[_SwiftValue.store(aKey)] {
30-
return _SwiftValue.fetch(val)
30+
return _SwiftValue.fetch(nonOptional: val)
3131
}
3232
return nil
3333
}
@@ -37,7 +37,7 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
3737
NSRequiresConcreteImplementation()
3838
}
3939

40-
return NSGeneratorEnumerator(_storage.keys.map { _SwiftValue.fetch($0) }.makeIterator())
40+
return NSGeneratorEnumerator(_storage.keys.map { _SwiftValue.fetch(nonOptional: $0) }.makeIterator())
4141
}
4242

4343
public override convenience init() {
@@ -186,8 +186,8 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
186186
open func getObjects(_ objects: inout [Any], andKeys keys: inout [Any], count: Int) {
187187
if type(of: self) === NSDictionary.self || type(of: self) === NSMutableDictionary.self {
188188
for (key, value) in _storage {
189-
keys.append(_SwiftValue.fetch(key))
190-
objects.append(_SwiftValue.fetch(value))
189+
keys.append(_SwiftValue.fetch(nonOptional: key))
190+
objects.append(_SwiftValue.fetch(nonOptional: value))
191191
}
192192
} else {
193193

Foundation/NSOrderedSet.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ open class NSOrderedSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
7070
}
7171

7272
open func object(at idx: Int) -> Any {
73-
return _SwiftValue.fetch(_orderedStorage[idx])
73+
return _SwiftValue.fetch(nonOptional: _orderedStorage[idx])
7474
}
7575

7676
open func index(of object: Any) -> Int {
@@ -121,7 +121,7 @@ open class NSOrderedSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
121121

122122
internal var allObjects: [Any] {
123123
if type(of: self) === NSOrderedSet.self || type(of: self) === NSMutableOrderedSet.self {
124-
return _orderedStorage.map { _SwiftValue.fetch($0) }
124+
return _orderedStorage.map { _SwiftValue.fetch(nonOptional: $0) }
125125
} else {
126126
return (0..<count).map { idx in
127127
return self[idx]
@@ -161,15 +161,15 @@ extension NSOrderedSet {
161161

162162
public var firstObject: Any? {
163163
if let value = _orderedStorage.first {
164-
return _SwiftValue.fetch(value)
164+
return _SwiftValue.fetch(nonOptional: value)
165165
} else {
166166
return nil
167167
}
168168
}
169169

170170
public var lastObject: Any? {
171171
if let value = _orderedStorage.last {
172-
return _SwiftValue.fetch(value)
172+
return _SwiftValue.fetch(nonOptional: value)
173173
} else {
174174
return nil
175175
}
@@ -234,19 +234,19 @@ extension NSOrderedSet {
234234
guard type(of: self) === NSOrderedSet.self || type(of: self) === NSMutableOrderedSet.self else {
235235
NSRequiresConcreteImplementation()
236236
}
237-
return NSGeneratorEnumerator(_orderedStorage.map { _SwiftValue.fetch($0) }.makeIterator())
237+
return NSGeneratorEnumerator(_orderedStorage.map { _SwiftValue.fetch(nonOptional: $0) }.makeIterator())
238238
}
239239

240240
public func reverseObjectEnumerator() -> NSEnumerator {
241241
guard type(of: self) === NSOrderedSet.self || type(of: self) === NSMutableOrderedSet.self else {
242242
NSRequiresConcreteImplementation()
243243
}
244-
return NSGeneratorEnumerator(_orderedStorage.map { _SwiftValue.fetch($0) }.reversed().makeIterator())
244+
return NSGeneratorEnumerator(_orderedStorage.map { _SwiftValue.fetch(nonOptional: $0) }.reversed().makeIterator())
245245
}
246246

247247
/*@NSCopying*/
248248
public var reversed: NSOrderedSet {
249-
return NSOrderedSet(array: _orderedStorage.map { _SwiftValue.fetch($0) }.reversed())
249+
return NSOrderedSet(array: _orderedStorage.map { _SwiftValue.fetch(nonOptional: $0) }.reversed())
250250
}
251251

252252
// These two methods return a facade object for the receiving ordered set,
@@ -548,7 +548,7 @@ extension NSMutableOrderedSet {
548548

549549
let swiftRange = range.toRange()!
550550
_orderedStorage[swiftRange].sort { lhs, rhs in
551-
return cmptr(_SwiftValue.fetch(lhs), _SwiftValue.fetch(rhs)) == .orderedAscending
551+
return cmptr(_SwiftValue.fetch(nonOptional: lhs), _SwiftValue.fetch(nonOptional: rhs)) == .orderedAscending
552552
}
553553
}
554554
}

Foundation/NSPropertyList.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ open class PropertyListSerialization : NSObject {
8484
if let err = error {
8585
throw err.takeUnretainedValue()._nsObject
8686
} else {
87-
return _SwiftValue.fetch(decoded!)
87+
return _SwiftValue.fetch(nonOptional: decoded!)
8888
}
8989
}
9090

@@ -104,7 +104,7 @@ open class PropertyListSerialization : NSObject {
104104
if let err = error {
105105
throw err.takeUnretainedValue()._nsObject
106106
} else {
107-
return _SwiftValue.fetch(decoded!)
107+
return _SwiftValue.fetch(nonOptional: decoded!)
108108
}
109109
}
110110

Foundation/NSSet.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ open class NSSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCodi
3434
guard type(of: self) === NSSet.self || type(of: self) === NSMutableSet.self || type(of: self) === NSCountedSet.self else {
3535
NSRequiresConcreteImplementation()
3636
}
37-
return NSGeneratorEnumerator(_storage.map { _SwiftValue.fetch($0) }.makeIterator())
37+
return NSGeneratorEnumerator(_storage.map { _SwiftValue.fetch(nonOptional: $0) }.makeIterator())
3838
}
3939

4040
public convenience override init() {
@@ -166,7 +166,7 @@ extension NSSet {
166166

167167
open var allObjects: [Any] {
168168
if type(of: self) === NSSet.self || type(of: self) === NSMutableSet.self {
169-
return _storage.map { _SwiftValue.fetch($0) }
169+
return _storage.map { _SwiftValue.fetch(nonOptional: $0) }
170170
} else {
171171
let enumerator = objectEnumerator()
172172
var items = [Any]()
@@ -219,7 +219,7 @@ extension NSSet {
219219
open func addingObjects(from other: Set<AnyHashable>) -> Set<AnyHashable> {
220220
var result = Set<AnyHashable>(minimumCapacity: Swift.max(count, other.count))
221221
if type(of: self) === NSSet.self || type(of: self) === NSMutableSet.self {
222-
result.formUnion(_storage.map { _SwiftValue.fetch($0) as! AnyHashable })
222+
result.formUnion(_storage.map { _SwiftValue.fetch(nonOptional: $0) as! AnyHashable })
223223
} else {
224224
for case let obj as NSObject in self {
225225
_ = result.insert(obj)
@@ -231,7 +231,7 @@ extension NSSet {
231231
open func addingObjects(from other: [Any]) -> Set<AnyHashable> {
232232
var result = Set<AnyHashable>(minimumCapacity: count)
233233
if type(of: self) === NSSet.self || type(of: self) === NSMutableSet.self {
234-
result.formUnion(_storage.map { _SwiftValue.fetch($0) as! AnyHashable })
234+
result.formUnion(_storage.map { _SwiftValue.fetch(nonOptional: $0) as! AnyHashable })
235235
} else {
236236
for case let obj as AnyHashable in self {
237237
result.insert(obj)

Foundation/NSUserDefaults.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ open class UserDefaults: NSObject {
150150
let bVal = aVal as? NSArray else {
151151
return nil
152152
}
153-
return _SwiftValue.fetch(bVal) as? [String]
153+
return _SwiftValue.fetch(nonOptional: bVal) as? [String]
154154
}
155155
open func integer(forKey defaultName: String) -> Int {
156156
guard let aVal = object(forKey: defaultName),

0 commit comments

Comments
 (0)