2012-02-16 21:48:57 -07:00
|
|
|
// run
|
2009-03-12 20:04:38 -06: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-18 19:19:43 -07:00
|
|
|
// Test typed integer constants.
|
|
|
|
|
2009-03-12 20:04:38 -06:00
|
|
|
package main
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
type T int
|
2010-03-24 17:46:53 -06:00
|
|
|
|
2010-06-14 18:16:35 -06:00
|
|
|
func (t T) String() string { return fmt.Sprintf("T%d", int(t)) }
|
2009-03-12 20:04:38 -06:00
|
|
|
|
|
|
|
const (
|
2010-03-24 17:46:53 -06:00
|
|
|
A T = 1 << (1 << iota)
|
|
|
|
B
|
|
|
|
C
|
|
|
|
D
|
|
|
|
E
|
2009-03-12 20:04:38 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2010-03-24 17:46:53 -06:00
|
|
|
s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E)
|
2009-03-12 20:04:38 -06:00
|
|
|
if s != "T2 T4 T16 T256 T65536" {
|
2010-03-24 17:46:53 -06:00
|
|
|
println("type info didn't propagate in const: got", s)
|
|
|
|
panic("fail")
|
2009-03-12 20:04:38 -06:00
|
|
|
}
|
2010-12-13 11:42:51 -07: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-12 20:04:38 -06:00
|
|
|
}
|