[swift-evolution] [Accepted] SE-0072: Fully eliminate implicit bridging conversions from Swift
Joe Groff
jgroff at apple.com
Mon May 9 12:08:46 CDT 2016
> On May 6, 2016, at 8:20 PM, Charles Srstka <cocoadev at charlessoft.com> wrote:
>
>> On May 6, 2016, at 3:15 PM, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
>>
>>> On May 6, 2016, at 12:21 PM, Jacob Bandes-Storch via swift-evolution <swift-evolution at swift.org> wrote:
>>>
>>> Does this affect the ability to use "x as? Int" (and similar) when x is an NSNumber?
>>
>> No, this only affects compile-time implicit conversions. I proposed changing the runtime behavior of dynamic casts in SE-0083:
>>
>> https://github.com/apple/swift-evolution/blob/master/proposals/0083-remove-bridging-from-dynamic-casts.md
>
> I’d just like to throw in that the ability to use “x as? Int” when x is an NSNumber is terrible.
>
> let num: AnyObject = NSNumber(int: 5)
>
> let int = num as? Int // 5
> let float = num as? Float // 5
> let int32 = num as? Int32 // nil!
>
> Completely unexpected failure, and you’ll never know about it until runtime.
My pitch to eliminate this casting behavior got pulled as SE-0083, up for review this week:
https://github.com/apple/swift-evolution/blob/master/proposals/0083-remove-bridging-from-dynamic-casts.md
-Joe
More information about the swift-evolution
mailing list