blob: 9bba6ced0b8bd109d02cfba5035302cc10475d3c [file] [log] [blame]
Russ Cox8f194bf2009-03-12 19:04:38 -07001// $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
7package main
8
9import "fmt"
10
11type T int
Rob Pike325cf8e2010-03-24 16:46:53 -070012
Rob Piked482c162010-06-14 17:16:35 -070013func (t T) String() string { return fmt.Sprintf("T%d", int(t)) }
Russ Cox8f194bf2009-03-12 19:04:38 -070014
15const (
Rob Pike325cf8e2010-03-24 16:46:53 -070016 A T = 1 << (1 << iota)
17 B
18 C
19 D
20 E
Russ Cox8f194bf2009-03-12 19:04:38 -070021)
22
23func main() {
Rob Pike325cf8e2010-03-24 16:46:53 -070024 s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E)
Russ Cox8f194bf2009-03-12 19:04:38 -070025 if s != "T2 T4 T16 T256 T65536" {
Rob Pike325cf8e2010-03-24 16:46:53 -070026 println("type info didn't propagate in const: got", s)
27 panic("fail")
Russ Cox8f194bf2009-03-12 19:04:38 -070028 }
Russ Cox603f9fe2010-12-13 13:42:51 -050029 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 Cox8f194bf2009-03-12 19:04:38 -070035}