From: Ken Thompson Date: Sun, 31 May 2009 20:02:24 +0000 (-0700) Subject: prevent multiple similar errors X-Git-Tag: weekly.2009-11-06~1500 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c17ce9f94fea5c3bf53312a5149dda11ba1ec8e1;p=gostls13.git prevent multiple similar errors in complex literals. side effect is fix of error in initializerr.go R=r OCL=29667 CL=29667 --- diff --git a/src/cmd/gc/sinit.c b/src/cmd/gc/sinit.c index a6727e0115..8fe3523918 100644 --- a/src/cmd/gc/sinit.c +++ b/src/cmd/gc/sinit.c @@ -464,9 +464,6 @@ initfix(Node* n) if(0) return xxx.list; -if(debug['A']) -dump("preinitfix", xxx.list); - // look for the copy-out reference r = listfirst(&iter, &xxx.list); while(r != N) { @@ -476,7 +473,5 @@ dump("preinitfix", xxx.list); } r = listnext(&iter); } -if(debug['A']) -dump("postinitfix", xxx.list); return xxx.list; } diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c index 1cfac55aff..c552c0928d 100644 --- a/src/cmd/gc/walk.c +++ b/src/cmd/gc/walk.c @@ -4084,9 +4084,10 @@ structlit(Node *n, Node *var) Iter savel, saver; Type *l, *t; Node *r, *a; - int mixflag; Node* hash[101]; + int nerr; + nerr = nerrors; t = n->type; if(t->etype != TSTRUCT) fatal("structlit: not struct"); @@ -4102,7 +4103,6 @@ structlit(Node *n, Node *var) if(r == N) return var; - mixflag = 0; if(r->op == OKEY) goto keyval; l = structfirst(&savel, &n->type); @@ -4112,16 +4112,16 @@ structlit(Node *n, Node *var) if(l == T) break; if(r->op == OKEY) { - mixflag = 1; // defer diagnostic - l = structnext(&savel); - r = listnext(&saver); - continue; + yyerror("mixture of value and field:value initializers"); + return var; } // build list of var.field = expr a = nod(ODOT, var, newname(l->sym)); a = nod(OAS, a, r); walktype(a, Etop); + if(nerr != nerrors) + return var; addtop = list(addtop, a); l = structnext(&savel); @@ -4131,8 +4131,6 @@ structlit(Node *n, Node *var) yyerror("struct literal expect expr of type %T", l); if(r != N) yyerror("struct literal too many expressions"); - if(mixflag) - yyerror("mixture of field:value initializers"); return var; keyval: @@ -4143,22 +4141,25 @@ keyval: while(r != N) { // assignment to field:value elements if(r->op != OKEY) { - mixflag = 1; - r = listnext(&saver); - continue; + yyerror("mixture of field:value and value initializers"); + break; } // build list of var.field = expr a = nod(ODOT, var, newname(r->left->sym)); fielddup(a->right, hash, nelem(hash)); + if(nerr != nerrors) + break; + a = nod(OAS, a, r->right); walktype(a, Etop); + if(nerr != nerrors) + break; + addtop = list(addtop, a); r = listnext(&saver); } - if(mixflag) - yyerror("mixture of field:value initializers"); return var; } @@ -4193,7 +4194,9 @@ arraylit(Node *n, Node *var) Node *r, *a; long ninit, b; Node* hash[101]; + int nerr; + nerr = nerrors; t = n->type; if(t->etype != TARRAY) fatal("arraylit: not array"); @@ -4263,12 +4266,23 @@ arraylit(Node *n, Node *var) } r = r->right; } + + if(t->bound >= 0 && b > t->bound) { + yyerror("array index out of bounds"); + break; + } + a = nodintconst(b); indexdup(a, hash, nelem(hash)); + if(nerr != nerrors) + break; + a = nod(OINDEX, var, a); a = nod(OAS, a, r); - walktype(a, Etop); // add any assignments in r to addtop + if(nerr != nerrors) + break; + addtop = list(addtop, a); b++; @@ -4339,7 +4353,9 @@ maplit(Node *n, Node *var) Type *t; Node *r, *a; Node* hash[101]; + int nerr; + nerr = nerrors; t = n->type; if(t->etype != TMAP) fatal("maplit: not map"); @@ -4370,10 +4386,15 @@ maplit(Node *n, Node *var) // build list of var[c] = expr keydup(r->left, hash, nelem(hash)); + if(nerr != nerrors) + break; a = nod(OINDEX, var, r->left); a = nod(OAS, a, r->right); walktype(a, Etop); + if(nerr != nerrors) + break; + addtop = list(addtop, a); r = listnext(&saver); diff --git a/test/golden.out b/test/golden.out index 131fc895b9..34f2d75ad7 100644 --- a/test/golden.out +++ b/test/golden.out @@ -26,9 +26,6 @@ panic PC=xxx =========== ./helloworld.go hello, world -=========== ./initializerr.go -BUG: errchk: ./initializerr.go:17: missing expected error: 'index|too many' - =========== ./peano.go 0! = 1 1! = 1