Rémy Oudompheng | 88b98ff | 2013-03-22 00:38:23 +0100 | [diff] [blame] | 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] |
Ian Lance Taylor | 161a45a | 2013-12-12 17:18:12 -0800 | [diff] [blame] | 31 | a3 = A[f2] // ERROR "truncated|must be integer" |
Rémy Oudompheng | 88b98ff | 2013-03-22 00:38:23 +0100 | [diff] [blame] | 32 | a4 = A[c] |
Ian Lance Taylor | 161a45a | 2013-12-12 17:18:12 -0800 | [diff] [blame] | 33 | a5 = A[c2] // ERROR "truncated|must be integer" |
Rémy Oudompheng | 7a0dc1c | 2013-06-28 23:08:07 +0200 | [diff] [blame] | 34 | a6 = A[vf] // ERROR "non-integer|must be integer" |
| 35 | a7 = A[vc] // ERROR "non-integer|must be integer" |
Rémy Oudompheng | 88b98ff | 2013-03-22 00:38:23 +0100 | [diff] [blame] | 36 | |
| 37 | s1 = S[i] |
| 38 | s2 = S[f] |
Ian Lance Taylor | 161a45a | 2013-12-12 17:18:12 -0800 | [diff] [blame] | 39 | s3 = S[f2] // ERROR "truncated|must be integer" |
Rémy Oudompheng | 88b98ff | 2013-03-22 00:38:23 +0100 | [diff] [blame] | 40 | s4 = S[c] |
Ian Lance Taylor | 161a45a | 2013-12-12 17:18:12 -0800 | [diff] [blame] | 41 | s5 = S[c2] // ERROR "truncated|must be integer" |
Rémy Oudompheng | 7a0dc1c | 2013-06-28 23:08:07 +0200 | [diff] [blame] | 42 | s6 = S[vf] // ERROR "non-integer|must be integer" |
| 43 | s7 = S[vc] // ERROR "non-integer|must be integer" |
Rémy Oudompheng | 88b98ff | 2013-03-22 00:38:23 +0100 | [diff] [blame] | 44 | |
| 45 | t1 = T[i] |
| 46 | t2 = T[f] |
Ian Lance Taylor | 161a45a | 2013-12-12 17:18:12 -0800 | [diff] [blame] | 47 | t3 = T[f2] // ERROR "truncated|must be integer" |
Rémy Oudompheng | 88b98ff | 2013-03-22 00:38:23 +0100 | [diff] [blame] | 48 | t4 = T[c] |
Ian Lance Taylor | 161a45a | 2013-12-12 17:18:12 -0800 | [diff] [blame] | 49 | t5 = T[c2] // ERROR "truncated|must be integer" |
Rémy Oudompheng | 7a0dc1c | 2013-06-28 23:08:07 +0200 | [diff] [blame] | 50 | t6 = T[vf] // ERROR "non-integer|must be integer" |
| 51 | t7 = T[vc] // ERROR "non-integer|must be integer" |
Rémy Oudompheng | 88b98ff | 2013-03-22 00:38:23 +0100 | [diff] [blame] | 52 | ) |