]> Cypherpunks repositories - gostls13.git/commitdiff
recognize a defined constant
authorKen Thompson <ken@golang.org>
Fri, 24 Apr 2009 23:43:31 +0000 (16:43 -0700)
committerKen Thompson <ken@golang.org>
Fri, 24 Apr 2009 23:43:31 +0000 (16:43 -0700)
as a new name in a later declaration
(bug 144)

R=r
OCL=27850
CL=27850

src/cmd/gc/go.y
src/cmd/gc/walk.c
test/fixedbugs/bug144.go [moved from test/bugs/bug144.go with 100% similarity]
test/golden.out

index 9cd7de11627188e81c9757ab6a10598aa17191db..47482a00ec4bd8dc7e735439cf5c95232adfe05f 100644 (file)
@@ -845,6 +845,7 @@ pexpr:
 |      laconst
        {
                $$ = nod(OLITERAL, N, N);
+               $$->sym = $1;
                $$->val = $1->oconst->val;
                $$->type = $1->oconst->type;
        }
index 798978b9a43a190064016b9fe07af5bdaa760d1d..fb7265980e5c28381b7ff87ac465b59bf6ee68b6 100644 (file)
@@ -3050,12 +3050,29 @@ out:
        return n;
 }
 
+int
+colasname(Node *n)
+{
+       switch(n->op) {
+       case ONAME:
+       case ONONAME:
+               break;
+       case OLITERAL:
+               if(n->sym != S)
+                       break;
+               // fallthrough
+       default:
+               return 0;
+       }
+       return 1;
+}
+
 Node*
 old2new(Node *n, Type *t)
 {
        Node *l;
 
-       if(n->op != ONAME && n->op != ONONAME) {
+       if(!colasname(n)) {
                yyerror("left side of := must be a name");
                return n;
        }
@@ -3092,7 +3109,7 @@ checkmixed(Node *nl)
                t = l->type;
                l = l->left;
 
-               if(l->op != ONAME && l->op != ONONAME)
+               if(!colasname(l))
                        goto allnew;
                if(l->sym->block == block) {
                        if(!eqtype(l->type, t, 0))
similarity index 100%
rename from test/bugs/bug144.go
rename to test/fixedbugs/bug144.go
index 1cfce4f28ae7c5a4a22ad95ff53553130576a971..b3cc4fb54334c0ad8c1a430cb1aeb92f3625ef6c 100644 (file)
@@ -121,14 +121,6 @@ bugs/bug140.go:6: syntax error near L1
 bugs/bug140.go:7: syntax error near L2
 BUG should compile
 
-=========== bugs/bug144.go
-bugs/bug144.go:8: left side of := must be a name
-bugs/bug144.go:8: operation LITERAL not allowed in assignment context
-bugs/bug144.go:8: illegal types for operand: AS
-       ideal
-       int
-BUG should compile
-
 =========== fixedbugs/bug016.go
 fixedbugs/bug016.go:7: constant -3 overflows uint