Source file
test/const3.go
1
2
3
4
5
6
7
8
9 package main
10
11 import "fmt"
12
13 type T int
14
15 func (t T) String() string { return fmt.Sprintf("T%d", int(t)) }
16
17 const (
18 A T = 1 << (1 << iota)
19 B
20 C
21 D
22 E
23 )
24
25 func main() {
26 s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E)
27 if s != "T2 T4 T16 T256 T65536" {
28 println("type info didn't propagate in const: got", s)
29 panic("fail")
30 }
31 x := uint(5)
32 y := float64(uint64(1)<<x)
33 if y != 32 {
34 println("wrong y", y)
35 panic("fail")
36 }
37 }
38
View as plain text