2012-02-17 04:48:57 +00:00
|
|
|
// run
|
2009-03-13 02:04:38 +00:00
|
|
|
|
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2012-02-19 02:19:43 +00:00
|
|
|
// Test typed integer constants.
|
|
|
|
|
2009-03-13 02:04:38 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
type T int
|
2010-03-24 23:46:53 +00:00
|
|
|
|
2010-06-15 00:16:35 +00:00
|
|
|
func (t T) String() string { return fmt.Sprintf("T%d", int(t)) }
|
2009-03-13 02:04:38 +00:00
|
|
|
|
|
|
|
const (
|
2010-03-24 23:46:53 +00:00
|
|
|
A T = 1 << (1 << iota)
|
|
|
|
B
|
|
|
|
C
|
|
|
|
D
|
|
|
|
E
|
2009-03-13 02:04:38 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2010-03-24 23:46:53 +00:00
|
|
|
s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E)
|
2009-03-13 02:04:38 +00:00
|
|
|
if s != "T2 T4 T16 T256 T65536" {
|
2010-03-24 23:46:53 +00:00
|
|
|
println("type info didn't propagate in const: got", s)
|
|
|
|
panic("fail")
|
2009-03-13 02:04:38 +00:00
|
|
|
}
|
2010-12-13 18:42:51 +00:00
|
|
|
x := uint(5)
|
|
|
|
y := float64(uint64(1)<<x) // used to fail to compile
|
|
|
|
if y != 32 {
|
|
|
|
println("wrong y", y)
|
|
|
|
panic("fail")
|
|
|
|
}
|
2009-03-13 02:04:38 +00:00
|
|
|
}
|