Another runnable example: package main
const x = 8 var y = 8 var a byte = 1 << x / 2 var b byte = 1 << y / 2 func main() { println(a) // 128 println(b) // 0 } On Thursday, June 3, 2021 at 10:42:32 AM UTC-4 peterGo wrote: > Jan, > > The untyped constant 1 assumes the type of x, which is float64. With > explicit types: > > package main > > import "fmt" > > func main() { > var a int = 0 > // invalid operation: float64(1) << a (shift of type float64) > var x float64 = float64(1) << a > fmt.Println(x) > } > > https://play.golang.org/p/jQ4k5qrxcTu > > Peter > > On Thursday, June 3, 2021 at 5:52:23 AM UTC-4 Jan Mercl wrote: > >> On Thu, Jun 3, 2021 at 11:21 AM Brian Candler <b.ca...@pobox.com> wrote: >> > >> > Weird. It simplifies to this: https://play.golang.org/p/OsOhRMC6kBu >> >> I think this case is WAI. >> >> From https://golang.org/ref/spec#Operators >> >> " If the left operand of a non-constant shift expression is an untyped >> constant, it is first implicitly converted to the type it would assume >> if the shift expression were replaced by its left operand alone." >> >> The OP case is strange in that the constness of the RHS operator >> somehow changes the interpretation of the above quotation >> specification, but I cannot find that it should. >> > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/cc7f17ce-25cf-4717-b063-98e4e18aae3fn%40googlegroups.com.