[swift-evolution] UInt64 indices broken

Xiaodi Wu xiaodi.wu at gmail.com
Thu Mar 16 12:14:33 CDT 2017


This is a deliberate design choice. As written in The Swift Programming
Language:

"Use UInt only when you specifically need an unsigned integer type with the
same size as the platform’s native word size. If this is not the case, Int
is preferred, even when the values to be stored are known to be
non-negative. A consistent use of Int for integer values aids code
interoperability, avoids the need to convert between different number
types, and matches integer type inference, as described in Type Safety and
Type Inference."

You are correct that arrays with count greater than Int.max are unsupported.
On Thu, Mar 16, 2017 at 11:13 G Alexander via swift-evolution <
swift-evolution at swift.org> wrote:

> All,
>
> Why does swift fails to fully implement UInt in any object, arrays,
> sequence, range, etc
>
> Initializer for Range, from "http://swiftdoc.org/v3.1/type/Range/"
>
>  For example, passing a closed range with an upper bound of Int.max
> triggers a runtime error, because the resulting half-open range would
> require an upper bound of Int.max + 1, which is not representable as an Int.
>
> So any algorithm that needs large arrays such that,   UInt64.max > index >
> Int64  too bad?
>
> _______________________________________________
> 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/20170316/6e23b773/attachment.html>


More information about the swift-evolution mailing list