void
colasdefn(NodeList *left, Node *defn)
{
- int nnew;
+ int nnew, nerr;
NodeList *l;
Node *n;
nnew = 0;
+ nerr = 0;
for(l=left; l; l=l->next) {
n = l->n;
if(isblank(n))
continue;
if(!colasname(n)) {
yyerror("non-name %#N on left side of :=", n);
+ nerr++;
continue;
}
if(n->sym->block == block)
defn->ninit = list(defn->ninit, nod(ODCL, n, N));
l->n = n;
}
- if(nnew == 0)
+ if(nnew == 0 && nerr == 0)
yyerror("no new variables on left side of :=");
}
ONOT, OCOM, OPLUS, OMINUS,
OOROR,
OPANIC, OPRINT, OPRINTN,
+ OPAREN,
OSEND,
OSLICE, OSLICEARR, OSLICESTR,
ORECOVER,
| '(' expr_or_type ')'
{
$$ = $2;
+
+ // Need to know on lhs of := whether there are ( ).
+ // Don't bother with the OPAREN in other cases:
+ // it's just a waste of memory and time.
+ switch($$->op) {
+ case ONAME:
+ case ONONAME:
+ case OPACK:
+ case OTYPE:
+ case OLITERAL:
+ $$ = nod(OPAREN, $$, N);
+ }
}
expr_or_type:
case OTPAREN:
case OINDEX:
case OINDEXMAP:
+ case OPAREN:
nprec = 7;
break;
fmtprint(f, "(node %O)", n->op);
break;
+ case OPAREN:
+ fmtprint(f, "(%#N)", n->left);
+ break;
+
case OREGISTER:
fmtprint(f, "%R", n->val.u.reg);
break;
n = *np;
if(n == N)
return N;
+
+ lno = setlineno(n);
+
+ // Skip over parens.
+ while(n->op == OPAREN)
+ n = n->left;
// Resolve definition of name and value of iota lazily.
n = resolve(n);
+
*np = n;
// Skip typecheck if already done.
--- /dev/null
+// errchk $G $D/$F.go
+
+// Copyright 2011 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+func main() {
+ (x) := 0 // ERROR "non-name [(]x[)]"
+}