Anomalous String.Index comparison

Hello. I've just joined the Forum. It's a tremendous pleasure to be here.

The reason for this thread is the following extract from Xcode's debugger.

(lldb) p range.upperBound
(String.Index) $R6 = (_rawBits = 1507328)
(lldb) p _string.endIndex
(String.Index) $R7 = (_rawBits = 1507329)
(lldb) p range.upperBound < _string.endIndex
(Bool) $R8 = false
(lldb) p range.upperBound == _string.endIndex
(Bool) $R9 = true
(lldb) p range.upperBound > _string.endIndex
(Bool) $R10 = false

Will someone please explain how the fuck two instances of String.Index with different values in rawBits can compare to equality?

Thank you.

String indices compare the top 48 bits (the offset). The bottom 16 bits are comprised of various flags, caches, etc. We're hoping to change String.Index's description to be more helpful and output things like the offset, some of these flags, etc. rather than just spitting out the raw bits integer.

4 Likes

Straight and to the point.