Debian Codegraph @

test/shift3.go

raw
1 // run
2
3 // Copyright 2022 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 // Test that the compiler's noder uses the correct type
8 // for RHS shift operands that are untyped. Must compile;
9 // run for good measure.
10
11 package main
12
13 import (
14 "fmt"
15 "math"
16 )
17
18 func f(x, y int) {
19 if x != y {
20 panic(fmt.Sprintf("%d != %d", x, y))
21 }
22 }
23
24 func main() {
25 var x int = 1
26 f(x<<1, 2)
27 f(x<<1., 2)
28 f(x<<(1+0i), 2)
29 f(x<<0i, 1)
30
31 f(x<<(1<<x), 4)
32 f(x<<(1.<<x), 4)
33 f(x<<((1+0i)<<x), 4)
34 f(x<<(0i<<x), 1)
35
36 // corner cases
37 const M = math.MaxUint
38 f(x<<(M+0), 0) // shift by untyped int representable as uint
39 f(x<<(M+0.), 0) // shift by untyped float representable as uint
40 f(x<<(M+0.+0i), 0) // shift by untyped complex representable as uint
41 }