This is because the value 1<<65-1<<64-1)
is not treated as a uint64
during the execution, but as a Constant Expression during the compilation, and may contain only Constants.
According to the specification:
Constant Expressions are Always evaluated Exactly; Intermediate values
and the constants themselves may require Precision significantly
Larger than supported by any predeclared type in the language.
Free translation:
Constant Expressions are always calculated accurately; intermediate values and constants themselves may require a
significantly greater precision than any type declared by
language.
According to the language specification, such constants (of the whole type) must be represented with at least 256 bits. The current version of the language supports an accuracy of up to 512 bits. If an operation is made that exceeds this limit, an error will be thrown. Example:
fmt.Print(uint64(1 << 512))
The above section generates the following error: shift count too large: 512
.
If the result of Constant Expression is a value greater than the supported or different from the declared type, the compiler will identify this as an error.