blob: f560b2fac98f3814a1ed28f09e85a5536316723d [file] [log] [blame]
Rémy Oudompheng88b98ff2013-03-22 00:38:23 +01001// 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
9package main
10
11var A [3]int
12var S []int
13var T string
14
15const (
16 i = 1
17 f = 2.0
18 f2 = 2.1
19 c = complex(2, 0)
20 c2 = complex(2, 1)
21)
22
23var (
24 vf = f
25 vc = c
26)
27
28var (
29 a1 = A[i]
30 a2 = A[f]
Ian Lance Taylor161a45a2013-12-12 17:18:12 -080031 a3 = A[f2] // ERROR "truncated|must be integer"
Rémy Oudompheng88b98ff2013-03-22 00:38:23 +010032 a4 = A[c]
Ian Lance Taylor161a45a2013-12-12 17:18:12 -080033 a5 = A[c2] // ERROR "truncated|must be integer"
Rémy Oudompheng7a0dc1c2013-06-28 23:08:07 +020034 a6 = A[vf] // ERROR "non-integer|must be integer"
35 a7 = A[vc] // ERROR "non-integer|must be integer"
Rémy Oudompheng88b98ff2013-03-22 00:38:23 +010036
37 s1 = S[i]
38 s2 = S[f]
Ian Lance Taylor161a45a2013-12-12 17:18:12 -080039 s3 = S[f2] // ERROR "truncated|must be integer"
Rémy Oudompheng88b98ff2013-03-22 00:38:23 +010040 s4 = S[c]
Ian Lance Taylor161a45a2013-12-12 17:18:12 -080041 s5 = S[c2] // ERROR "truncated|must be integer"
Rémy Oudompheng7a0dc1c2013-06-28 23:08:07 +020042 s6 = S[vf] // ERROR "non-integer|must be integer"
43 s7 = S[vc] // ERROR "non-integer|must be integer"
Rémy Oudompheng88b98ff2013-03-22 00:38:23 +010044
45 t1 = T[i]
46 t2 = T[f]
Ian Lance Taylor161a45a2013-12-12 17:18:12 -080047 t3 = T[f2] // ERROR "truncated|must be integer"
Rémy Oudompheng88b98ff2013-03-22 00:38:23 +010048 t4 = T[c]
Ian Lance Taylor161a45a2013-12-12 17:18:12 -080049 t5 = T[c2] // ERROR "truncated|must be integer"
Rémy Oudompheng7a0dc1c2013-06-28 23:08:07 +020050 t6 = T[vf] // ERROR "non-integer|must be integer"
51 t7 = T[vc] // ERROR "non-integer|must be integer"
Rémy Oudompheng88b98ff2013-03-22 00:38:23 +010052)