swiftlang / swift-corelibs-foundation

The Foundation Project, providing core utilities, internationalization, and OS independence
swift.org
Apache License 2.0
5.3k stars 1.14k forks source link

[SR-8407] NSNumber as? Bool behaves differently on Swift 4.2 #3660

Closed swift-ci closed 6 years ago

swift-ci commented 6 years ago
Previous ID SR-8407
Radar None
Original Reporter guidomb (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment Ubuntu 16.04 Swift version 4.2-dev (LLVM da1c9a3ae4, Clang 78aa734eee, Swift fe1f442af0)
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Foundation | |Labels | Bug | |Assignee | @spevans | |Priority | Medium | md5: 5a624138e0df69b003fa2f905bee94d2

Issue Description:

It seems there is a regression, at least comparing Swift 4.2 snapshot 2018-07-28 with 2018-06-21 (on linux) when trying to optionally cast a instance of NSNumber to Bool. Here is a snippet that reproduces the issue

import Foundation

let a = NSNumber(value: 10)
let b: Any = a
print("\(b as? Bool)")

On macOS with Swift 4.1 the output is nil. On Linux with Swift 4.2 snapshot 2018-07-28 the output is Optional(true).

belkadan commented 6 years ago

cc @phausler

spevans commented 6 years ago

https://github.com/apple/swift-corelibs-foundation/pull/1642

spevans commented 6 years ago

This has been merged into master and the swift-4.2-branch now

belkadan commented 6 years ago

Ah, in general the person who filed the bug should be the one to close it. The person who fixes it can use "Verify" instead.

belkadan commented 6 years ago

Er, that should be "Resolved", of course. Radar terminology getting the better of me.