mirror of
https://github.com/golang/go
synced 2024-11-02 11:50:30 +00:00
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:
parent
83ac901fb9
commit
2ca99505f6
3 changed files with 14 additions and 2 deletions
|
@ -2525,8 +2525,9 @@ typecheckcomplit(Node **np)
|
||||||
typecheck(&l->left, Erv);
|
typecheck(&l->left, Erv);
|
||||||
evconst(l->left);
|
evconst(l->left);
|
||||||
i = nonnegconst(l->left);
|
i = nonnegconst(l->left);
|
||||||
if(i < 0) {
|
if(i < 0 && !l->left->diag) {
|
||||||
yyerror("array index must be non-negative integer constant");
|
yyerror("array index must be non-negative integer constant");
|
||||||
|
l->left->diag = 1;
|
||||||
i = -(1<<30); // stay negative for a while
|
i = -(1<<30); // stay negative for a while
|
||||||
}
|
}
|
||||||
if(i >= 0)
|
if(i >= 0)
|
||||||
|
|
|
@ -9,6 +9,6 @@ package main
|
||||||
var x int
|
var x int
|
||||||
|
|
||||||
var a = []int{ x: 1} // ERROR "constant"
|
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}
|
var c = map[int]int{ x: 1}
|
||||||
|
|
||||||
|
|
11
test/fixedbugs/issue7153.go
Normal file
11
test/fixedbugs/issue7153.go
Normal 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"
|
Loading…
Reference in a new issue