[swift-evolution] [Accepted] SE-0072: Fully eliminate implicit bridging conversions from Swift

Jacob Bandes-Storch jtbandes at gmail.com
Fri May 6 23:01:39 CDT 2016


Agreed, but I'm sure lots of user code depends on it (e.g. when extracting
numeric values from property lists). If it stopped working, wouldn't these
"as?" casts silently start returning nil where they didn't before?
On Fri, 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.
>
> Charles
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160507/2545bdec/attachment.html>


More information about the swift-evolution mailing list