mirror of https://github.com/golang/go.git
cmd/gc: silence redundant error prints for misuse of [...]int
Fixes #4452. R=ken2 CC=golang-dev https://golang.org/cl/7241065
This commit is contained in:
parent
e2711cb202
commit
f607c479ea
|
|
@ -253,8 +253,12 @@ dowidth(Type *t)
|
||||||
checkwidth(t->type);
|
checkwidth(t->type);
|
||||||
t->align = widthptr;
|
t->align = widthptr;
|
||||||
}
|
}
|
||||||
else if(t->bound == -100)
|
else if(t->bound == -100) {
|
||||||
yyerror("use of [...] array outside of array literal");
|
if(!t->broke) {
|
||||||
|
yyerror("use of [...] array outside of array literal");
|
||||||
|
t->broke = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
fatal("dowidth %T", t); // probably [...]T
|
fatal("dowidth %T", t); // probably [...]T
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -240,7 +240,8 @@ convlit1(Node **np, Type *t, int explicit)
|
||||||
|
|
||||||
bad:
|
bad:
|
||||||
if(!n->diag) {
|
if(!n->diag) {
|
||||||
yyerror("cannot convert %N to type %T", n, t);
|
if(!t->broke)
|
||||||
|
yyerror("cannot convert %N to type %T", n, t);
|
||||||
n->diag = 1;
|
n->diag = 1;
|
||||||
}
|
}
|
||||||
if(isideal(n->type)) {
|
if(isideal(n->type)) {
|
||||||
|
|
|
||||||
|
|
@ -377,8 +377,11 @@ reswitch:
|
||||||
t->bound = -1; // slice
|
t->bound = -1; // slice
|
||||||
} else if(l->op == ODDD) {
|
} else if(l->op == ODDD) {
|
||||||
t->bound = -100; // to be filled in
|
t->bound = -100; // to be filled in
|
||||||
if(!(top&Ecomplit))
|
if(!(top&Ecomplit) && !n->diag) {
|
||||||
|
t->broke = 1;
|
||||||
|
n->diag = 1;
|
||||||
yyerror("use of [...] array outside of array literal");
|
yyerror("use of [...] array outside of array literal");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
l = typecheck(&n->left, Erv);
|
l = typecheck(&n->left, Erv);
|
||||||
switch(consttype(l)) {
|
switch(consttype(l)) {
|
||||||
|
|
@ -1028,8 +1031,11 @@ reswitch:
|
||||||
defaultlit(&n->left, T);
|
defaultlit(&n->left, T);
|
||||||
l = n->left;
|
l = n->left;
|
||||||
if(l->op == OTYPE) {
|
if(l->op == OTYPE) {
|
||||||
if(n->isddd || l->type->bound == -100)
|
if(n->isddd || l->type->bound == -100) {
|
||||||
yyerror("invalid use of ... in type conversion", l);
|
if(!l->type->broke)
|
||||||
|
yyerror("invalid use of ... in type conversion", l);
|
||||||
|
n->diag = 1;
|
||||||
|
}
|
||||||
// pick off before type-checking arguments
|
// pick off before type-checking arguments
|
||||||
ok |= Erv;
|
ok |= Erv;
|
||||||
// turn CALL(type, arg) into CONV(arg) w/ type
|
// turn CALL(type, arg) into CONV(arg) w/ type
|
||||||
|
|
@ -1335,7 +1341,10 @@ reswitch:
|
||||||
if((t = n->left->type) == T || n->type == T)
|
if((t = n->left->type) == T || n->type == T)
|
||||||
goto error;
|
goto error;
|
||||||
if((n->op = convertop(t, n->type, &why)) == 0) {
|
if((n->op = convertop(t, n->type, &why)) == 0) {
|
||||||
yyerror("cannot convert %lN to type %T%s", n->left, n->type, why);
|
if(!n->diag && !n->type->broke) {
|
||||||
|
yyerror("cannot convert %lN to type %T%s", n->left, n->type, why);
|
||||||
|
n->diag = 1;
|
||||||
|
}
|
||||||
n->op = OCONV;
|
n->op = OCONV;
|
||||||
}
|
}
|
||||||
switch(n->op) {
|
switch(n->op) {
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
// 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 4452. Used to print many errors, now just one.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
_ = [...]int(4) // ERROR "use of \[\.\.\.\] array outside of array literal"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue