]> Cypherpunks repositories - gostls13.git/commitdiff
prevent multiple similar errors
authorKen Thompson <ken@golang.org>
Sun, 31 May 2009 20:02:24 +0000 (13:02 -0700)
committerKen Thompson <ken@golang.org>
Sun, 31 May 2009 20:02:24 +0000 (13:02 -0700)
in complex literals. side effect is
fix of error in initializerr.go

R=r
OCL=29667
CL=29667

src/cmd/gc/sinit.c
src/cmd/gc/walk.c
test/golden.out

index a6727e01153ac11ee3853db2c19cb210a205c19a..8fe3523918ec3cd10b4666ef6ddbb3a1f0165efd 100644 (file)
@@ -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;
 }
index 1cfac55affd824cab09f8d115148e1b7c277c7b7..c552c0928d78a802aa28c6c8eaced5e2860e64c0 100644 (file)
@@ -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);
index 131fc895b91021e2683bf5cbaceb49e8285abdc8..34f2d75ad7951b7e391ccf60af3ff6b41f67c1fb 100644 (file)
@@ -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