]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/gc: Specify which package import caused an redeclaration error.
authorDaniel Morsing <daniel.morsing@gmail.com>
Thu, 13 Sep 2012 16:40:50 +0000 (18:40 +0200)
committerDaniel Morsing <daniel.morsing@gmail.com>
Thu, 13 Sep 2012 16:40:50 +0000 (18:40 +0200)
Fixes #4012.

R=dave, remyoudompheng, rsc
CC=golang-dev
https://golang.org/cl/6490082

src/cmd/gc/dcl.c
src/cmd/gc/export.c
src/cmd/gc/go.h
src/cmd/gc/subr.c

index 63a55c74b1318a9cdddc0defd61ad4c9cc8ece5f..1f50910526f58a21fcae08728d5bf72e78eb3b76 100644 (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);
index bbed8ae36e18e168ae10712770029e01ebd746e2..77a82dafb863ff7b8f17a08cc54c03ec8630c819 100644 (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) {
index 5ce9fb9e94e5bcc82afdb9ea67728ac29a2a2ede..67793bd4358ac80f3b32e06a5fd1e7c8a72cc489 100644 (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)
 
index 0cd7e6c4b0d3e42b0b5dfc5243fe98f993479834..c04c1edc7100100dd71ed053b3eef1b421951413 100644 (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++;
                }
        }