Compiler in Xcode cannot type-check long bit-shifting expression
codeanticode opened this issue · 2 comments
codeanticode commented
Describe the bug
Latest version of the XCode compiler (tested on XCode Version 13.3 (13E113)) give an error on this line:
saying that the line cannot be type-checked because the expression is too long… See the screenshot from XCode highlighting the error message:
A simple solution seems to break up the bit-shifting operation into two separate operations, as suggested by the compiler:
func uint64(_ index: Int) -> UInt64? {
let bytes = [UInt8](self)
guard index < (bytes.count - 7) else {
return nil
}
let a = UInt64(bytes[index]) |
UInt64(bytes[index + 1]) << 8 |
UInt64(bytes[index + 2]) << 16 |
UInt64(bytes[index + 3]) << 24 |
UInt64(bytes[index + 4]) << 32
let b = UInt64(bytes[index + 5]) << 40 |
UInt64(bytes[index + 6]) << 48 |
UInt64(bytes[index + 7]) << 56
return a | b
}
adamfowleruk commented
How very bizarre. Thanks for the bug report. I'll verify on my Mac soon.
codeanticode commented
@adamfowleruk Although it seems rare, people have reported it (for other complex instructions, not bitwise operations):
and there is some more info about it here:
I created a PR with the fix: #174