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