Skip to content

NSNumber: Forced bridging an invalid value would not trap. #2959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions Sources/Foundation/NSNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ extension Int8 : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout Int8?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout Int8?) -> Bool {
Expand Down Expand Up @@ -87,7 +89,9 @@ extension UInt8 : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt8?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt8?) -> Bool {
Expand Down Expand Up @@ -125,7 +129,9 @@ extension Int16 : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout Int16?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout Int16?) -> Bool {
Expand Down Expand Up @@ -163,7 +169,9 @@ extension UInt16 : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt16?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt16?) -> Bool {
Expand Down Expand Up @@ -201,7 +209,9 @@ extension Int32 : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout Int32?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout Int32?) -> Bool {
Expand Down Expand Up @@ -239,7 +249,9 @@ extension UInt32 : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt32?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt32?) -> Bool {
Expand Down Expand Up @@ -277,7 +289,9 @@ extension Int64 : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout Int64?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout Int64?) -> Bool {
Expand Down Expand Up @@ -315,7 +329,9 @@ extension UInt64 : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt64?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt64?) -> Bool {
Expand Down Expand Up @@ -353,7 +369,9 @@ extension Int : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout Int?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout Int?) -> Bool {
Expand Down Expand Up @@ -391,7 +409,9 @@ extension UInt : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout UInt?) -> Bool {
Expand Down Expand Up @@ -437,7 +457,9 @@ extension Float : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout Float?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout Float?) -> Bool {
Expand Down Expand Up @@ -488,7 +510,9 @@ extension Double : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout Double?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout Double?) -> Bool {
Expand Down Expand Up @@ -533,7 +557,9 @@ extension Bool : _ObjectiveCBridgeable {
}

public static func _forceBridgeFromObjectiveC(_ x: NSNumber, result: inout Bool?) {
result = _unconditionallyBridgeFromObjectiveC(x)
if !_conditionallyBridgeFromObjectiveC(x, result: &result) {
fatalError("Unable to bridge \(type(of: x)) to \(self)")
}
}

public static func _conditionallyBridgeFromObjectiveC(_ x: NSNumber, result: inout Bool?) -> Bool {
Expand Down