summaryrefslogtreecommitdiff
path: root/test/fixedbugs/issue4813.go
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2013-05-14 18:39:35 +0200
committerMichael Stapelberg <michael@stapelberg.de>2013-05-14 18:39:35 +0200
commitefcc50dfdc94c82ee0292bf71992ecb7c0123061 (patch)
tree17dca99d1dc7fc4e9fe49c2cf6a99d337d4c039f /test/fixedbugs/issue4813.go
parent04b08da9af0c450d645ab7389d1467308cfc2db8 (diff)
downloadgolang-efcc50dfdc94c82ee0292bf71992ecb7c0123061.tar.gz
Imported Upstream version 1.1upstream/1.1
Diffstat (limited to 'test/fixedbugs/issue4813.go')
-rw-r--r--test/fixedbugs/issue4813.go52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/fixedbugs/issue4813.go b/test/fixedbugs/issue4813.go
new file mode 100644
index 000000000..0ca9d3f72
--- /dev/null
+++ b/test/fixedbugs/issue4813.go
@@ -0,0 +1,52 @@
+// errorcheck
+
+// Copyright 2013 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.
+
+// Issue 4813: use of constant floats as indices.
+
+package main
+
+var A [3]int
+var S []int
+var T string
+
+const (
+ i = 1
+ f = 2.0
+ f2 = 2.1
+ c = complex(2, 0)
+ c2 = complex(2, 1)
+)
+
+var (
+ vf = f
+ vc = c
+)
+
+var (
+ a1 = A[i]
+ a2 = A[f]
+ a3 = A[f2] // ERROR "truncated"
+ a4 = A[c]
+ a5 = A[c2] // ERROR "truncated"
+ a6 = A[vf] // ERROR "non-integer"
+ a7 = A[vc] // ERROR "non-integer"
+
+ s1 = S[i]
+ s2 = S[f]
+ s3 = S[f2] // ERROR "truncated"
+ s4 = S[c]
+ s5 = S[c2] // ERROR "truncated"
+ s6 = S[vf] // ERROR "non-integer"
+ s7 = S[vc] // ERROR "non-integer"
+
+ t1 = T[i]
+ t2 = T[f]
+ t3 = T[f2] // ERROR "truncated"
+ t4 = T[c]
+ t5 = T[c2] // ERROR "truncated"
+ t6 = T[vf] // ERROR "non-integer"
+ t7 = T[vc] // ERROR "non-integer"
+)