Fixes #13365.
Change-Id: I5a447ff806dbbb11c8c75e2b5cfa7fd4a845fb92
Reviewed-on: https://go-review.googlesource.com/17206
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
}
length := int64(0)
i := 0
- var l *Node
for ll := n.List; ll != nil; ll = ll.Next {
- l = ll.N
+ l := ll.N
setlineno(l)
if l.Op != OKEY {
l = Nod(OKEY, Nodintconst(int64(i)), l)
evconst(l.Left)
i = nonnegconst(l.Left)
if i < 0 && l.Left.Diag == 0 {
- Yyerror("array index must be non-negative integer constant")
+ Yyerror("index must be non-negative integer constant")
l.Left.Diag = 1
i = -(1 << 30) // stay negative for a while
}
pushtype(r, t.Type)
typecheck(&r, Erv)
defaultlit(&r, t.Type)
- l.Right = assignconv(r, t.Type, "array element")
+ l.Right = assignconv(r, t.Type, "array or slice literal")
}
if t.Bound == -100 {
--- /dev/null
+// errorcheck
+
+// Copyright 2015 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 13365: confusing error message (array vs slice)
+
+package main
+
+var t struct{}
+
+func main() {
+ _ = []int{-1: 0} // ERROR "index must be non\-negative integer constant"
+ _ = [10]int{-1: 0} // ERROR "index must be non\-negative integer constant"
+ _ = [...]int{-1: 0} // ERROR "index must be non\-negative integer constant"
+
+ _ = []int{100: 0}
+ _ = [10]int{100: 0} // ERROR "array index 100 out of bounds"
+ _ = [...]int{100: 0}
+
+ _ = []int{t} // ERROR "cannot use .* as type int in array or slice literal"
+ _ = [10]int{t} // ERROR "cannot use .* as type int in array or slice literal"
+ _ = [...]int{t} // ERROR "cannot use .* as type int in array or slice literal"
+}
package main
func main() {
- _ = [0]int{-1: 50} // ERROR "array index must be non-negative integer constant"
- _ = [0]int{0: 0} // ERROR "array index 0 out of bounds \[0:0\]"
- _ = [0]int{5: 25} // ERROR "array index 5 out of bounds \[0:0\]"
- _ = [10]int{2: 10, 15: 30} // ERROR "array index 15 out of bounds \[0:10\]"
- _ = [10]int{5: 5, 1: 1, 12: 12} // ERROR "array index 12 out of bounds \[0:10\]"
+ _ = [0]int{-1: 50} // ERROR "index must be non-negative integer constant"
+ _ = [0]int{0: 0} // ERROR "index 0 out of bounds \[0:0\]"
+ _ = [0]int{5: 25} // ERROR "index 5 out of bounds \[0:0\]"
+ _ = [10]int{2: 10, 15: 30} // ERROR "index 15 out of bounds \[0:10\]"
+ _ = [10]int{5: 5, 1: 1, 12: 12} // ERROR "index 12 out of bounds \[0:10\]"
}
package p
-var _ = []int{a: true, true} // ERROR "undefined: a" "cannot use true \(type bool\) as type int in array element"
+var _ = []int{a: true, true} // ERROR "undefined: a" "cannot use true \(type bool\) as type int in array or slice literal"