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);
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) {
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)
Sym *s, *s1;
uint32 h;
int n;
+ char *pkgerror;
n = 0;
for(h=0; h<NHASH; h++) {
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++;
}
}