1
0
mirror of https://github.com/golang/go synced 2024-11-21 20:54:45 -07:00

cmd/gc: Specify which package import caused an redeclaration error.

Fixes #4012.

R=dave, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6490082
This commit is contained in:
Daniel Morsing 2012-09-13 18:40:50 +02:00
parent ecc04b8927
commit d06dcd4595
4 changed files with 18 additions and 7 deletions

View File

@ -150,11 +150,14 @@ testdclstack(void)
void
redeclare(Sym *s, char *where)
{
if(s->lastlineno == 0)
Strlit *pkgstr;
if(s->lastlineno == 0) {
pkgstr = s->origpkg ? s->origpkg->path : s->pkg->path;
yyerror("%S redeclared %s\n"
"\tprevious declaration during import",
s, where);
else
"\tprevious declaration during import \"%Z\"",
s, where, pkgstr);
} else
yyerror("%S redeclared %s\n"
"\tprevious declaration at %L",
s, where, s->lastlineno);

View File

@ -349,8 +349,12 @@ dumpexport(void)
Sym*
importsym(Sym *s, int op)
{
if(s->def != N && s->def->op != op)
redeclare(s, "during import");
char *pkgstr;
if(s->def != N && s->def->op != op) {
pkgstr = smprint("during import \"%Z\"", importpkg->path);
redeclare(s, pkgstr);
}
// mark the symbol so it is not reexported
if(s->def == N) {

View File

@ -365,6 +365,7 @@ struct Sym
Label* label; // corresponding label (ephemeral)
int32 block; // blocknumber to catch redeclaration
int32 lastlineno; // last declaration for diagnostic
Pkg* origpkg; // original package for . import
};
#define S ((Sym*)0)

View File

@ -382,6 +382,7 @@ importdot(Pkg *opkg, Node *pack)
Sym *s, *s1;
uint32 h;
int n;
char *pkgerror;
n = 0;
for(h=0; h<NHASH; h++) {
@ -394,12 +395,14 @@ importdot(Pkg *opkg, Node *pack)
continue;
s1 = lookup(s->name);
if(s1->def != N) {
redeclare(s1, "during import");
pkgerror = smprint("during import \"%Z\"", opkg->path);
redeclare(s1, pkgerror);
continue;
}
s1->def = s->def;
s1->block = s->block;
s1->def->pack = pack;
s1->origpkg = opkg;
n++;
}
}