From: Ken Thompson Date: Fri, 24 Apr 2009 23:43:31 +0000 (-0700) Subject: recognize a defined constant X-Git-Tag: weekly.2009-11-06~1765 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b03b541b7a8834d31e00efa11911eb8aacfe4746;p=gostls13.git recognize a defined constant as a new name in a later declaration (bug 144) R=r OCL=27850 CL=27850 --- diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 9cd7de1162..47482a00ec 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -845,6 +845,7 @@ pexpr: | laconst { $$ = nod(OLITERAL, N, N); + $$->sym = $1; $$->val = $1->oconst->val; $$->type = $1->oconst->type; } diff --git a/src/cmd/gc/walk.c b/src/cmd/gc/walk.c index 798978b9a4..fb7265980e 100644 --- a/src/cmd/gc/walk.c +++ b/src/cmd/gc/walk.c @@ -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)) diff --git a/test/bugs/bug144.go b/test/fixedbugs/bug144.go similarity index 100% rename from test/bugs/bug144.go rename to test/fixedbugs/bug144.go diff --git a/test/golden.out b/test/golden.out index 1cfce4f28a..b3cc4fb543 100644 --- a/test/golden.out +++ b/test/golden.out @@ -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