Commit b03b541b authored by Ken Thompson's avatar Ken Thompson

recognize a defined constant

as a new name in a later declaration
(bug 144)

R=r
OCL=27850
CL=27850
parent 9c3a9b71
......@@ -845,6 +845,7 @@ pexpr:
| laconst
{
$$ = nod(OLITERAL, N, N);
$$->sym = $1;
$$->val = $1->oconst->val;
$$->type = $1->oconst->type;
}
......
......@@ -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))
......
......@@ -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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment