github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/test/fixedbugs/issue4813.go (about) 1 // errorcheck 2 3 // Copyright 2013 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 // Issue 4813: use of constant floats as indices. 8 9 package main 10 11 var A [3]int 12 var S []int 13 var T string 14 15 const ( 16 i = 1 17 f = 2.0 18 f2 = 2.1 19 c = complex(2, 0) 20 c2 = complex(2, 1) 21 ) 22 23 var ( 24 vf = f 25 vc = c 26 ) 27 28 var ( 29 a1 = A[i] 30 a2 = A[f] 31 a3 = A[f2] // ERROR "truncated" 32 a4 = A[c] 33 a5 = A[c2] // ERROR "truncated" 34 a6 = A[vf] // ERROR "non-integer" 35 a7 = A[vc] // ERROR "non-integer" 36 37 s1 = S[i] 38 s2 = S[f] 39 s3 = S[f2] // ERROR "truncated" 40 s4 = S[c] 41 s5 = S[c2] // ERROR "truncated" 42 s6 = S[vf] // ERROR "non-integer" 43 s7 = S[vc] // ERROR "non-integer" 44 45 t1 = T[i] 46 t2 = T[f] 47 t3 = T[f2] // ERROR "truncated" 48 t4 = T[c] 49 t5 = T[c2] // ERROR "truncated" 50 t6 = T[vf] // ERROR "non-integer" 51 t7 = T[vc] // ERROR "non-integer" 52 )