]> Cypherpunks repositories - gostls13.git/commitdiff
declared and not used error, but disabled.
authorRuss Cox <rsc@golang.org>
Tue, 15 Sep 2009 01:38:30 +0000 (18:38 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 15 Sep 2009 01:38:30 +0000 (18:38 -0700)
fix some bugs involving _.

R=ken
OCL=34621
CL=34621

src/cmd/gc/gen.c
src/cmd/gc/go.h
src/cmd/gc/go.y
src/cmd/gc/typecheck.c
src/cmd/gc/walk.c

index a64b0a3ca26b2bd9f82cd60f3365cea158fb5c58..8c00c58987498d9a5883fc3c384fc393735b4217 100644 (file)
@@ -26,6 +26,7 @@ allocparams(void)
        Node *n;
        uint32 w;
        Sym *s;
+       int lno;
 
        if(stksize < 0)
                fatal("allocparams not during code generation");
@@ -35,6 +36,7 @@ allocparams(void)
         * slots for all automatics.
         * allocated starting at -w down.
         */
+       lno = lineno;
        for(l=curfn->dcl; l; l=l->next) {
                n = l->n;
                if(n->op == ONAME && n->class == PHEAP-1) {
@@ -46,19 +48,21 @@ allocparams(void)
                }
                if(n->op != ONAME || n->class != PAUTO)
                        continue;
-               typecheck(&n, Erv);     // only needed for unused variables
+               lineno = n->lineno;
+               typecheck(&n, Erv | Easgn);     // only needed for unused variables
                if(n->type == T)
                        continue;
+       //      if(!n->used && n->sym->name[0] != '&')
+       //              yyerror("%S declared and not used", n->sym);
                dowidth(n->type);
                w = n->type->width;
-               if(n->class & PHEAP)
-                       w = widthptr;
                if(w >= 100000000)
                        fatal("bad width");
                stksize += w;
                stksize = rnd(stksize, w);
                n->xoffset = -stksize;
        }
+       lineno = lno;
 }
 
 void
index 93c900db3218c1e17ce8d3fe1d0e32d3e63242d6..aa2e6d89d6534d5be5e912fe74cfa03526ac5576 100644 (file)
@@ -201,6 +201,7 @@ struct      Node
        uchar   local;
        uchar   initorder;
        uchar   dodata;         // compile literal assignment as data statement
+       uchar   used;
 
        // most nodes
        Node*   left;
index 61f8b2b2ee40a4323c1513fc56a0c3446e985992..ea9cd3aed57caf3cba16adcd5e25321e269eadb0 100644 (file)
@@ -456,6 +456,7 @@ case:
                if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
                        // type switch - declare variable
                        n = newname(n->sym);
+                       n->used = 1;    // TODO(rsc): better job here
                        declare(n, dclcontext);
                        $$->nname = n;
                }
@@ -488,6 +489,7 @@ case:
                if(typesw != N && typesw->right != N && (n=typesw->right->left) != N) {
                        // type switch - declare variable
                        n = newname(n->sym);
+                       n->used = 1;    // TODO(rsc): better job here
                        declare(n, dclcontext);
                        $$->nname = n;
                }
index d33e9e8094736e48223770fb9e0dc68c7fa6e8c4..308ed90e3374b485e59781c8d906982482c5ba1b 100644 (file)
@@ -112,9 +112,13 @@ reswitch:
                        ok |= Ecall;
                        goto ret;
                }
-               if(isblank(n) && !(top & Easgn)) {
-                       yyerror("cannot use _ as value");
-                       goto error;
+               if(!(top & Easgn)) {
+                       // not a write to the variable
+                       if(isblank(n)) {
+                               yyerror("cannot use _ as value");
+                               goto error;
+                       }
+                       n->used = 1;
                }
                ok |= Erv;
                goto ret;
index 6f5dde32820470f86084631cdf16c72977b14a89..e66a42ce23bfacbe598f2dfd7d16e9b995b3b39f 100644 (file)
@@ -1771,6 +1771,9 @@ convas(Node *n, NodeList **init)
        if(lt == T || rt == T)
                goto out;
 
+       if(isblank(n->left))
+               goto out;
+
        if(n->left->op == OINDEXMAP) {
                n = mkcall1(mapfn("mapassign1", n->left->left->type), T, init,
                        n->left->left, n->left->right, n->right);