cmd/gc: suppress array index error caused by a previously reported error

Fixes #7153

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/82180043
This commit is contained in:
Jan Ziak 2014-03-29 15:45:40 +01:00
parent 83ac901fb9
commit 2ca99505f6
3 changed files with 14 additions and 2 deletions

View 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)

View 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}

View file

@ -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"