1
0
mirror of https://github.com/golang/go synced 2024-11-21 17:34:40 -07:00

cmd/gc: point "no new variables" error at right line number.

Fixes #3856.

R=dsymonds, rsc
CC=golang-dev
https://golang.org/cl/6455056
This commit is contained in:
Daniel Morsing 2012-07-29 22:24:19 -04:00 committed by Russ Cox
parent be629bf79e
commit dd166b9437
7 changed files with 499 additions and 499 deletions

View File

@ -464,7 +464,7 @@ colasdefn(NodeList *left, Node *defn)
if(isblank(n))
continue;
if(!colasname(n)) {
yyerror("non-name %N on left side of :=", n);
yyerrorl(defn->lineno, "non-name %N on left side of :=", n);
nerr++;
continue;
}
@ -479,11 +479,11 @@ colasdefn(NodeList *left, Node *defn)
l->n = n;
}
if(nnew == 0 && nerr == 0)
yyerror("no new variables on left side of :=");
yyerrorl(defn->lineno, "no new variables on left side of :=");
}
Node*
colas(NodeList *left, NodeList *right)
colas(NodeList *left, NodeList *right, int32 lno)
{
Node *as;
@ -491,6 +491,7 @@ colas(NodeList *left, NodeList *right)
as->list = left;
as->rlist = right;
as->colas = 1;
as->lineno = lno;
colasdefn(left, as);
// make the tree prettier; not necessary

View File

@ -928,7 +928,7 @@ void nodfconst(Node *n, Type *t, Mpflt* fval);
void addmethod(Sym *sf, Type *t, int local);
void addvar(Node *n, Type *t, int ctxt);
NodeList* checkarglist(NodeList *all, int input);
Node* colas(NodeList *left, NodeList *right);
Node* colas(NodeList *left, NodeList *right, int32 lno);
void colasdefn(NodeList *left, Node *defn);
NodeList* constiter(NodeList *vl, Node *t, NodeList *cl);
Node* dclname(Sym *s);

View File

@ -37,8 +37,8 @@ static void fixlbrace(int);
// |sed 's/.* //' |9 fmt -l1 |sort |9 fmt -l50 | sed 's/^/%xxx /'
%token <val> LLITERAL
%token <i> LASOP
%token <sym> LBREAK LCASE LCHAN LCOLAS LCONST LCONTINUE LDDD
%token <i> LASOP LCOLAS
%token <sym> LBREAK LCASE LCHAN LCONST LCONTINUE LDDD
%token <sym> LDEFAULT LDEFER LELSE LFALL LFOR LFUNC LGO LGOTO
%token <sym> LIF LIMPORT LINTERFACE LMAP LNAME
%token <sym> LPACKAGE LRANGE LRETURN LSELECT LSTRUCT LSWITCH
@ -437,7 +437,7 @@ simple_stmt:
$$->left = dclname($1->n->sym); // it's a colas, so must not re-use an oldname.
break;
}
$$ = colas($1, $3);
$$ = colas($1, $3, $2);
}
| expr LINC
{
@ -496,7 +496,7 @@ case:
// done in casebody()
markdcl();
$$ = nod(OXCASE, N, N);
$$->list = list1(colas($2, list1($4)));
$$->list = list1(colas($2, list1($4), $3));
}
| LDEFAULT ':'
{

View File

@ -973,6 +973,7 @@ l0:
c1 = getc();
if(c1 == '=') {
c = LCOLAS;
yylval.i = lexlineno;
goto lx;
}
break;

File diff suppressed because it is too large Load Diff

View File

@ -39,10 +39,10 @@
enum yytokentype {
LLITERAL = 258,
LASOP = 259,
LBREAK = 260,
LCASE = 261,
LCHAN = 262,
LCOLAS = 263,
LCOLAS = 260,
LBREAK = 261,
LCASE = 262,
LCHAN = 263,
LCONST = 264,
LCONTINUE = 265,
LDDD = 266,
@ -91,10 +91,10 @@
/* Tokens. */
#define LLITERAL 258
#define LASOP 259
#define LBREAK 260
#define LCASE 261
#define LCHAN 262
#define LCOLAS 263
#define LCOLAS 260
#define LBREAK 261
#define LCASE 262
#define LCHAN 263
#define LCONST 264
#define LCONTINUE 265
#define LDDD 266

View File

@ -38,6 +38,12 @@ func main() {
i, f := f2() // ERROR "redeclared|no new"
_, _, _ = i, f, s
}
{
// multiline no new variables
i := f1
i := func() int { // ERROR "redeclared|no new|incompatible"
}
}
{
// single redeclaration
i, f, s := f3()