]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: suppress array index error caused by a previously reported error
authorJan Ziak <0xe2.0x9a.0x9b@gmail.com>
Sat, 29 Mar 2014 14:45:40 +0000 (15:45 +0100)
committerJan Ziak <0xe2.0x9a.0x9b@gmail.com>
Sat, 29 Mar 2014 14:45:40 +0000 (15:45 +0100)
Fixes #7153

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/82180043

src/cmd/gc/typecheck.c
test/fixedbugs/bug176.go
test/fixedbugs/issue7153.go [new file with mode: 0644]

index f6e77acebdbc18abc39c47b9ee78928b4d3b2dcb..5a025a15b6016a98dd997cf9590c35841519874f 100644 (file)
@@ -2525,8 +2525,9 @@ typecheckcomplit(Node **np)
                        typecheck(&l->left, Erv);
                        evconst(l->left);
                        i = nonnegconst(l->left);
-                       if(i < 0) {
+                       if(i < 0 && !l->left->diag) {
                                yyerror("array index must be non-negative integer constant");
+                               l->left->diag = 1;
                                i = -(1<<30);   // stay negative for a while
                        }
                        if(i >= 0)
index 82f8dba0ad0b5ec71d97df454ddd10907a22d171..ea3a9097477dc7b1238f43e311061da389e9d9ba 100644 (file)
@@ -9,6 +9,6 @@ package main
 var x int
 
 var a = []int{ x: 1}   // ERROR "constant"
-var b = [...]int{ x : 1}       // ERROR "constant"
+var b = [...]int{x: 1}
 var c = map[int]int{ x: 1}
 
diff --git a/test/fixedbugs/issue7153.go b/test/fixedbugs/issue7153.go
new file mode 100644 (file)
index 0000000..d70d858
--- /dev/null
@@ -0,0 +1,11 @@
+// errorcheck
+
+// Copyright 2014 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 7153: array invalid index error duplicated on successive bad values
+
+package p
+
+var _ = []int{a: true, true} // ERROR "undefined: a" "cannot use true \(type bool\) as type int in array element"