Commit 5a5799f6 authored by Russ Cox's avatar Russ Cox

gc: more precise handling of import .

Fixes #455.

R=ken2
CC=golang-dev
https://golang.org/cl/186212
parent 07fc1457
...@@ -149,6 +149,11 @@ testdclstack(void) ...@@ -149,6 +149,11 @@ testdclstack(void)
void void
redeclare(Sym *s, char *where) redeclare(Sym *s, char *where)
{ {
if(s->lastlineno == 0)
yyerror("%S redeclared %s\n"
"\tprevious declaration during import",
s, where);
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);
......
...@@ -1470,9 +1470,9 @@ mkpackage(char* pkg) ...@@ -1470,9 +1470,9 @@ mkpackage(char* pkg)
if(s->def->op == OPACK) { if(s->def->op == OPACK) {
// throw away top-level package name leftover // throw away top-level package name leftover
// from previous file. // from previous file.
// TODO(rsc): remember that there was a package // leave s->block set to cause redeclaration
// name, so that the name cannot be redeclared // errors if a conflicting top-level name is
// as a non-package in other files. // introduced by a different file.
if(!s->def->used && !nsyntaxerrors) if(!s->def->used && !nsyntaxerrors)
yyerrorl(s->def->lineno, "imported and not used: %s", s->def->sym->name); yyerrorl(s->def->lineno, "imported and not used: %s", s->def->sym->name);
s->def = N; s->def = N;
......
...@@ -353,6 +353,7 @@ importdot(Sym *opkg, Node *pack) ...@@ -353,6 +353,7 @@ importdot(Sym *opkg, Node *pack)
continue; continue;
} }
s1->def = s->def; s1->def = s->def;
s1->block = s->block;
s1->def->pack = pack; s1->def->pack = pack;
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