mirror of
https://github.com/golang/go
synced 2024-10-14 11:53:56 +00:00
cmd/gc: prohibit short variable declarations containing duplicate symbols
Fixes #6764. Fixes #8435. LGTM=rsc R=golang-codereviews, r, gobot, rsc CC=golang-codereviews https://golang.org/cl/116440046
This commit is contained in:
parent
1eea5caa30
commit
55df81d37f
|
@ -488,6 +488,10 @@ colasdefn(NodeList *left, Node *defn)
|
||||||
NodeList *l;
|
NodeList *l;
|
||||||
Node *n;
|
Node *n;
|
||||||
|
|
||||||
|
for(l=left; l; l=l->next)
|
||||||
|
if(l->n->sym != S)
|
||||||
|
l->n->sym->flags |= SymUniq;
|
||||||
|
|
||||||
nnew = 0;
|
nnew = 0;
|
||||||
nerr = 0;
|
nerr = 0;
|
||||||
for(l=left; l; l=l->next) {
|
for(l=left; l; l=l->next) {
|
||||||
|
@ -499,6 +503,13 @@ colasdefn(NodeList *left, Node *defn)
|
||||||
nerr++;
|
nerr++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if((n->sym->flags & SymUniq) == 0) {
|
||||||
|
yyerrorl(defn->lineno, "%S repeated on left side of :=", n->sym);
|
||||||
|
n->diag++;
|
||||||
|
nerr++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
n->sym->flags &= ~SymUniq;
|
||||||
if(n->sym->block == block)
|
if(n->sym->block == block)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|
|
@ -53,4 +53,16 @@ func main() {
|
||||||
_ = x
|
_ = x
|
||||||
_ = y
|
_ = y
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
var x = 1
|
||||||
|
{
|
||||||
|
x, x := 2, 3 // ERROR "x repeated on left side of :="
|
||||||
|
_ = x
|
||||||
|
}
|
||||||
|
_ = x
|
||||||
|
}
|
||||||
|
{
|
||||||
|
a, a := 1, 2 // ERROR "a repeated on left side of :="
|
||||||
|
_ = a
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue