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 <[email protected]> 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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/b8061835-44fb-4bcf-9017-d2c9a6b58608n%40googlegroups.com.