Source file test/const3.go

     1  // run
     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  
     7  // Test typed integer constants.
     8  
     9  package main
    10  
    11  import "fmt"
    12  
    13  type T int
    14  
    15  func (t T) String() string { return fmt.Sprintf("T%d", int(t)) }
    16  
    17  const (
    18  	A T = 1 << (1 << iota)
    19  	B
    20  	C
    21  	D
    22  	E
    23  )
    24  
    25  func main() {
    26  	s := fmt.Sprintf("%v %v %v %v %v", A, B, C, D, E)
    27  	if s != "T2 T4 T16 T256 T65536" {
    28  		println("type info didn't propagate in const: got", s)
    29  		panic("fail")
    30  	}
    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  	}
    37  }
    38  

View as plain text