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

Conversation

spevans
Copy link
Contributor

@spevans spevans commented Dec 23, 2020

  • eg NSNumber(value: 1.2) as! Int would return 0 instead of trapping.
    Exit with fatalError() if the bridging failed.

  • This matches Darwin.

Cant add a test for trapping behaviour but a toolchain was tested v 5.3.1

$ cat bridge.swift 
import Foundation

let x = NSNumber(value: 1.2) as? Int
let y = NSNumber(value: 1.2) as! Int
print(x as Any, y)

$ ~/swift-5.3.1-RELEASE-ubuntu20.04/usr/bin/swift bridge.swift 
nil 0

$ ~/swift-build/toolchains/main-test/usr/bin/swift bridge.swift 
Foundation/NSNumber.swift:373: Fatal error: Unable to bridge NSNumber to Int
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
.
.
.
Illegal instruction (core dumped)

- eg `NSNumber(value: 1.2) as! Int` would return 0 instead of trapping.
  Exit with fatalError() if the bridging failed.

- This matches Darwin.
@spevans
Copy link
Contributor Author

spevans commented Dec 23, 2020

@swift-ci test

1 similar comment
@spevans
Copy link
Contributor Author

spevans commented Jan 4, 2021

@swift-ci test

@spevans spevans merged commit cf74d83 into swiftlang:main Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant