Commit 6aaa86ff authored by Russ Cox's avatar Russ Cox

gc: avoid package name ambiguity in error messages

Fixes #2006.

R=ken2
CC=golang-dev
https://golang.org/cl/4643056
parent 19f79504
...@@ -302,6 +302,7 @@ struct Sym ...@@ -302,6 +302,7 @@ struct Sym
uchar flags; uchar flags;
uchar sym; // huffman encoding in object file uchar sym; // huffman encoding in object file
Sym* link; Sym* link;
int32 npkg; // number of imported packages with this name
// saved and restored by dcopy // saved and restored by dcopy
Pkg* pkg; Pkg* pkg;
...@@ -777,6 +778,7 @@ EXTERN int32 nhunk; ...@@ -777,6 +778,7 @@ EXTERN int32 nhunk;
EXTERN int32 thunk; EXTERN int32 thunk;
EXTERN int exporting; EXTERN int exporting;
EXTERN int erroring;
EXTERN int noargnames; EXTERN int noargnames;
EXTERN int funcdepth; EXTERN int funcdepth;
......
...@@ -238,6 +238,7 @@ import_package: ...@@ -238,6 +238,7 @@ import_package:
LPACKAGE sym import_safety ';' LPACKAGE sym import_safety ';'
{ {
importpkg->name = $2->name; importpkg->name = $2->name;
pkglookup($2->name, nil)->npkg++;
importpkg->direct = 1; importpkg->direct = 1;
if(safemode && !curio.importsafe) if(safemode && !curio.importsafe)
...@@ -1658,6 +1659,7 @@ hidden_import: ...@@ -1658,6 +1659,7 @@ hidden_import:
p = mkpkg($3.u.sval); p = mkpkg($3.u.sval);
p->name = $2->name; p->name = $2->name;
pkglookup($2->name, nil)->npkg++;
} }
| LVAR hidden_pkg_importsym hidden_type ';' | LVAR hidden_pkg_importsym hidden_type ';'
{ {
......
...@@ -45,10 +45,12 @@ adderr(int line, char *fmt, va_list arg) ...@@ -45,10 +45,12 @@ adderr(int line, char *fmt, va_list arg)
Fmt f; Fmt f;
Error *p; Error *p;
erroring++;
fmtstrinit(&f); fmtstrinit(&f);
fmtprint(&f, "%L: ", line); fmtprint(&f, "%L: ", line);
fmtvprint(&f, fmt, arg); fmtvprint(&f, fmt, arg);
fmtprint(&f, "\n"); fmtprint(&f, "\n");
erroring--;
if(nerr >= merr) { if(nerr >= merr) {
if(merr == 0) if(merr == 0)
...@@ -1123,6 +1125,13 @@ Sconv(Fmt *fp) ...@@ -1123,6 +1125,13 @@ Sconv(Fmt *fp)
} }
if(s->pkg != localpkg || longsymnames || (fp->flags & FmtLong)) { if(s->pkg != localpkg || longsymnames || (fp->flags & FmtLong)) {
// This one is for the user. If the package name
// was used by multiple packages, give the full
// import path to disambiguate.
if(erroring && pkglookup(s->pkg->name, nil)->npkg > 1) {
fmtprint(fp, "\"%Z\".%s", s->pkg->path, s->name);
return 0;
}
fmtprint(fp, "%s.%s", s->pkg->name, s->name); fmtprint(fp, "%s.%s", s->pkg->name, s->name);
return 0; return 0;
} }
......
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package io
type Writer interface {
WrongWrite()
}
type SectionReader struct {
X int
}
func SR(*SectionReader) {}
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"bufio"
"./io"
goio "io"
)
func main() {
// The errors here complain that io.X != io.X
// for different values of io so they should be
// showing the full import path, which for the
// "./io" import is really ..../go/test/io.
// For example:
//
// main.go:25: cannot use w (type "/Users/rsc/g/go/test/fixedbugs/bug345.dir/io".Writer) as type "io".Writer in function argument:
// io.Writer does not implement io.Writer (missing Write method)
// main.go:27: cannot use &x (type *"io".SectionReader) as type *"/Users/rsc/g/go/test/fixedbugs/bug345.dir/io".SectionReader in function argument
var w io.Writer
bufio.NewWriter(w) // ERROR "test/io"
var x goio.SectionReader
io.SR(&x) // ERROR "test/io"
}
// $G $D/$F.dir/io.go && errchk $G -e $D/$F.dir/main.go
// Copyright 2011 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package ignored
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