Commit d06dcd45 authored by Daniel Morsing's avatar Daniel Morsing

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

Fixes #4012.

R=dave, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6490082
parent ecc04b89
...@@ -150,11 +150,14 @@ testdclstack(void) ...@@ -150,11 +150,14 @@ testdclstack(void)
void void
redeclare(Sym *s, char *where) 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" yyerror("%S redeclared %s\n"
"\tprevious declaration during import", "\tprevious declaration during import \"%Z\"",
s, where); s, where, pkgstr);
else } else
yyerror("%S redeclared %s\n" yyerror("%S redeclared %s\n"
"\tprevious declaration at %L", "\tprevious declaration at %L",
s, where, s->lastlineno); s, where, s->lastlineno);
......
...@@ -349,8 +349,12 @@ dumpexport(void) ...@@ -349,8 +349,12 @@ dumpexport(void)
Sym* Sym*
importsym(Sym *s, int op) importsym(Sym *s, int op)
{ {
if(s->def != N && s->def->op != op) char *pkgstr;
redeclare(s, "during import");
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 // mark the symbol so it is not reexported
if(s->def == N) { if(s->def == N) {
......
...@@ -365,6 +365,7 @@ struct Sym ...@@ -365,6 +365,7 @@ struct Sym
Label* label; // corresponding label (ephemeral) Label* label; // corresponding label (ephemeral)
int32 block; // blocknumber to catch redeclaration int32 block; // blocknumber to catch redeclaration
int32 lastlineno; // last declaration for diagnostic int32 lastlineno; // last declaration for diagnostic
Pkg* origpkg; // original package for . import
}; };
#define S ((Sym*)0) #define S ((Sym*)0)
......
...@@ -382,6 +382,7 @@ importdot(Pkg *opkg, Node *pack) ...@@ -382,6 +382,7 @@ importdot(Pkg *opkg, Node *pack)
Sym *s, *s1; Sym *s, *s1;
uint32 h; uint32 h;
int n; int n;
char *pkgerror;
n = 0; n = 0;
for(h=0; h<NHASH; h++) { for(h=0; h<NHASH; h++) {
...@@ -394,12 +395,14 @@ importdot(Pkg *opkg, Node *pack) ...@@ -394,12 +395,14 @@ importdot(Pkg *opkg, Node *pack)
continue; continue;
s1 = lookup(s->name); s1 = lookup(s->name);
if(s1->def != N) { if(s1->def != N) {
redeclare(s1, "during import"); pkgerror = smprint("during import \"%Z\"", opkg->path);
redeclare(s1, pkgerror);
continue; continue;
} }
s1->def = s->def; s1->def = s->def;
s1->block = s->block; s1->block = s->block;
s1->def->pack = pack; s1->def->pack = pack;
s1->origpkg = opkg;
n++; n++;
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment