cmd/gc: fix imported and not used error for import .

Fixes issues 6420.

R=ken2
CC=golang-dev
https://golang.org/cl/13703044
This commit is contained in:
Russ Cox 2013-09-20 15:25:43 -04:00
parent 36f8480965
commit 5be1821a31
2 changed files with 4 additions and 3 deletions

View file

@ -2296,7 +2296,7 @@ pkgnotused(int lineno, Strlit *path, char *name)
elem++;
else
elem = path->s;
if(strcmp(elem, name) == 0)
if(name == nil || strcmp(elem, name) == 0)
yyerrorl(lineno, "imported and not used: \"%Z\"", path);
else
yyerrorl(lineno, "imported and not used: \"%Z\" as %s", path, name);
@ -2335,7 +2335,7 @@ mkpackage(char* pkgname)
// throw away top-level name left over
// from previous import . "x"
if(s->def->pack != N && !s->def->pack->used && !nsyntaxerrors) {
pkgnotused(s->def->pack->lineno, s->def->pack->pkg->path, s->name);
pkgnotused(s->def->pack->lineno, s->def->pack->pkg->path, nil);
s->def->pack->used = 1;
}
s->def = N;

View file

@ -14,5 +14,6 @@ import bufio "os" // ERROR "redeclared|redefinition|incompatible" "imported and
import (
"fmt" // GCCGO_ERROR "previous|not used"
fmt "math" // ERROR "redeclared|redefinition|incompatible" "imported and not used"
fmt "math" // ERROR "redeclared|redefinition|incompatible" "imported and not used: \x22math\x22 as fmt"
. "math" // ERROR "imported and not used: \x22math\x22$"
)