1
0
mirror of https://github.com/golang/go synced 2024-11-21 22:34:48 -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)) if(isblank(n))
continue; continue;
if(!colasname(n)) { if(!colasname(n)) {
yyerror("non-name %N on left side of :=", n); yyerrorl(defn->lineno, "non-name %N on left side of :=", n);
nerr++; nerr++;
continue; continue;
} }
@ -479,11 +479,11 @@ colasdefn(NodeList *left, Node *defn)
l->n = n; l->n = n;
} }
if(nnew == 0 && nerr == 0) if(nnew == 0 && nerr == 0)
yyerror("no new variables on left side of :="); yyerrorl(defn->lineno, "no new variables on left side of :=");
} }
Node* Node*
colas(NodeList *left, NodeList *right) colas(NodeList *left, NodeList *right, int32 lno)
{ {
Node *as; Node *as;
@ -491,6 +491,7 @@ colas(NodeList *left, NodeList *right)
as->list = left; as->list = left;
as->rlist = right; as->rlist = right;
as->colas = 1; as->colas = 1;
as->lineno = lno;
colasdefn(left, as); colasdefn(left, as);
// make the tree prettier; not necessary // 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 addmethod(Sym *sf, Type *t, int local);
void addvar(Node *n, Type *t, int ctxt); void addvar(Node *n, Type *t, int ctxt);
NodeList* checkarglist(NodeList *all, int input); 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); void colasdefn(NodeList *left, Node *defn);
NodeList* constiter(NodeList *vl, Node *t, NodeList *cl); NodeList* constiter(NodeList *vl, Node *t, NodeList *cl);
Node* dclname(Sym *s); 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 /' // |sed 's/.* //' |9 fmt -l1 |sort |9 fmt -l50 | sed 's/^/%xxx /'
%token <val> LLITERAL %token <val> LLITERAL
%token <i> LASOP %token <i> LASOP LCOLAS
%token <sym> LBREAK LCASE LCHAN LCOLAS LCONST LCONTINUE LDDD %token <sym> LBREAK LCASE LCHAN LCONST LCONTINUE LDDD
%token <sym> LDEFAULT LDEFER LELSE LFALL LFOR LFUNC LGO LGOTO %token <sym> LDEFAULT LDEFER LELSE LFALL LFOR LFUNC LGO LGOTO
%token <sym> LIF LIMPORT LINTERFACE LMAP LNAME %token <sym> LIF LIMPORT LINTERFACE LMAP LNAME
%token <sym> LPACKAGE LRANGE LRETURN LSELECT LSTRUCT LSWITCH %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. $$->left = dclname($1->n->sym); // it's a colas, so must not re-use an oldname.
break; break;
} }
$$ = colas($1, $3); $$ = colas($1, $3, $2);
} }
| expr LINC | expr LINC
{ {
@ -496,7 +496,7 @@ case:
// done in casebody() // done in casebody()
markdcl(); markdcl();
$$ = nod(OXCASE, N, N); $$ = nod(OXCASE, N, N);
$$->list = list1(colas($2, list1($4))); $$->list = list1(colas($2, list1($4), $3));
} }
| LDEFAULT ':' | LDEFAULT ':'
{ {

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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