]> Cypherpunks repositories - gostls13.git/commitdiff
gc: more precise handling of import .
authorRuss Cox <rsc@golang.org>
Tue, 19 Jan 2010 00:26:40 +0000 (16:26 -0800)
committerRuss Cox <rsc@golang.org>
Tue, 19 Jan 2010 00:26:40 +0000 (16:26 -0800)
Fixes #455.

R=ken2
CC=golang-dev
https://golang.org/cl/186212

src/cmd/gc/dcl.c
src/cmd/gc/lex.c
src/cmd/gc/subr.c

index c9fcb1204a6b210c10871354f5ba88da6d8611d2..adf8da9bc0dd700344695beb96137f8d9bd19343 100644 (file)
@@ -149,9 +149,14 @@ testdclstack(void)
 void
 redeclare(Sym *s, char *where)
 {
-       yyerror("%S redeclared %s\n"
-               "\tprevious declaration at %L",
-               s, where, s->lastlineno);
+       if(s->lastlineno == 0)
+               yyerror("%S redeclared %s\n"
+                       "\tprevious declaration during import",
+                       s, where);
+       else
+               yyerror("%S redeclared %s\n"
+                       "\tprevious declaration at %L",
+                       s, where, s->lastlineno);
 }
 
 /*
index d74cb096ad65d5411733b614947608bbf5741d29..c433c1ec9e904f8ef48ab2b7ab3eb9aab571ea2b 100644 (file)
@@ -1470,9 +1470,9 @@ mkpackage(char* pkg)
                                if(s->def->op == OPACK) {
                                        // throw away top-level package name leftover
                                        // from previous file.
-                                       // TODO(rsc): remember that there was a package
-                                       // name, so that the name cannot be redeclared
-                                       // as a non-package in other files.
+                                       // leave s->block set to cause redeclaration
+                                       // errors if a conflicting top-level name is
+                                       // introduced by a different file.
                                        if(!s->def->used && !nsyntaxerrors)
                                                yyerrorl(s->def->lineno, "imported and not used: %s", s->def->sym->name);
                                        s->def = N;
index f38992b74052e451acede2bf913375b38106e4d3..f7abc0357e3cbf3a64dad837cc98b996917963de 100644 (file)
@@ -353,6 +353,7 @@ importdot(Sym *opkg, Node *pack)
                                continue;
                        }
                        s1->def = s->def;
+                       s1->block = s->block;
                        s1->def->pack = pack;
                        n++;
                }