[swift-evolution] Warning for possible overflow or optional

David Turnbull dturnbull at gmail.com
Tue Feb 16 12:02:46 CST 2016


This is perfectly safe since it's checked at runtime. If you don't want it
checked at runtime you can use Int16(bitPattern: x).

I just finished writing the inflate algorithm in Swift. With your
suggestion I would have used bitPattern or truncatingBitPattern everywhere
to bypass warnings and missed at least two times where Swift caught a
mistake a runtime. C API users would have a similar problem.

-david  https://github.com/AE9RB/SwiftGL

On Tue, Feb 16, 2016 at 4:45 AM, Stéphane Lizeray <swift-evolution at swift.org
> wrote:

> Hello,
>
>
> Don’t you think that the compiler should emit a warning for a possible
> overflow in the following code?
>
>
> func foo(x:UInt16) {
>
> let y = Int16(x) <— Shouldn’t we have a warning here? Or an optional?
> print(y)
> }
>
> This code is very very fragile and Swift is supposed to bring safety?
>
>
> Thanks,
>
>
> Stéphane
>
>
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160216/61774501/attachment.html>


More information about the swift-evolution mailing list