From 21d03496e7b6e7c32a0b6f5a76abab0c9e9c086b Mon Sep 17 00:00:00 2001
From: Rob Pike -1e12
can be assigned to a
but not uint64
or string
.
+If a typed constant expression evaluates to a value that is not +representable by that type, the compiler reports an error. +
+ ++uint8(-1) // error, out of range +uint8(100) * 100 // error, out of range ++ +
+The size of the mask used by the unary bitwise complement +operator in a typed constant expression is equal to the size of the +expression's type. In an ideal constant expression, the bitwise +complement operator inverts all the bits, producing a negative value. +
+ ++^1 // ideal constant, equal to -2 +uint8(^1) // error, same as uint8(-2), out of range +^uint8(1) // typed uint8 constant, same as 0xFF ^ uint8(1) = uint8(0xFE) +int8(^1) // same as int8(-2) +^int8(1) // error, same as 0xFF ^ int8(1) = int8(0xFE), out of range ++ +
+TODO: perhaps ^ should be disallowed on non-uints instead of assuming twos complement. +Also it may be possible to make typed constants more like variables, at the cost of fewer +overflow etc. errors being caught. +
+