Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 1 | // $G $D/$F.go && $L $F.$A && ./$A.out |
| 2 | |
| 3 | // Copyright 2009 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 | package main |
| 8 | |
| 9 | import "fmt" |
| 10 | |
| 11 | type T int |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 12 | |
Rob Pike | d482c16 | 2010-06-14 17:16:35 -0700 | [diff] [blame] | 13 | func (t T) String() string { return fmt.Sprintf("T%d", int(t)) } |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 14 | |
| 15 | const ( |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 16 | A T = 1 << (1 << iota) |
| 17 | B |
| 18 | C |
| 19 | D |
| 20 | E |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 21 | ) |
| 22 | |
| 23 | func main() { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 24 | s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E) |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 25 | if s != "T2 T4 T16 T256 T65536" { |
Rob Pike | 325cf8e | 2010-03-24 16:46:53 -0700 | [diff] [blame] | 26 | println("type info didn't propagate in const: got", s) |
| 27 | panic("fail") |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 28 | } |
Russ Cox | 603f9fe | 2010-12-13 13:42:51 -0500 | [diff] [blame] | 29 | x := uint(5) |
| 30 | y := float64(uint64(1)<<x) // used to fail to compile |
| 31 | if y != 32 { |
| 32 | println("wrong y", y) |
| 33 | panic("fail") |
| 34 | } |
Russ Cox | 8f194bf | 2009-03-12 19:04:38 -0700 | [diff] [blame] | 35 | } |