blob: 3f4e3d1ae6fa9adf095afe91e176daa3708fe86b [file] [log] [blame]
Russ Cox0b477ef2012-02-16 23:48:57 -05001// run
Russ Cox8f194bf2009-03-12 19:04:38 -07002
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 Pikefc0dc042012-02-19 13:19:43 +11007// Test typed integer constants.
8
Russ Cox8f194bf2009-03-12 19:04:38 -07009package main
10
11import "fmt"
12
13type T int
Rob Pike325cf8e2010-03-24 16:46:53 -070014
Rob Piked482c162010-06-14 17:16:35 -070015func (t T) String() string { return fmt.Sprintf("T%d", int(t)) }
Russ Cox8f194bf2009-03-12 19:04:38 -070016
17const (
Rob Pike325cf8e2010-03-24 16:46:53 -070018 A T = 1 << (1 << iota)
19 B
20 C
21 D
22 E
Russ Cox8f194bf2009-03-12 19:04:38 -070023)
24
25func main() {
Rob Pike325cf8e2010-03-24 16:46:53 -070026 s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E)
Russ Cox8f194bf2009-03-12 19:04:38 -070027 if s != "T2 T4 T16 T256 T65536" {
Rob Pike325cf8e2010-03-24 16:46:53 -070028 println("type info didn't propagate in const: got", s)
29 panic("fail")
Russ Cox8f194bf2009-03-12 19:04:38 -070030 }
Russ Cox603f9fe2010-12-13 13:42:51 -050031 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 Cox8f194bf2009-03-12 19:04:38 -070037}