From 3f686cae848063601233e61dccc026b3e8ce5d5a Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 13 Nov 2013 16:03:41 -0500 Subject: [PATCH] go.tools/go/types: print named types with package qualification. Depending on the context, printing only the package name can be ambiguous or even incorrect since it is valid only within the environment of a given file's import specs. (The standard library packages are mostly unique in their last segment, but this is not the case for proprietary repos.) R=gri, gri CC=golang-dev https://golang.org/cl/26300043 --- go/types/api_test.go | 2 +- go/types/errors.go | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/go/types/api_test.go b/go/types/api_test.go index de161a766e6..8c74d6b00f7 100644 --- a/go/types/api_test.go +++ b/go/types/api_test.go @@ -23,7 +23,7 @@ func pkgFor(path, source string, info *Info) (*Package, error) { } var conf Config - pkg, err := conf.Check(path, fset, []*ast.File{f}, info) + pkg, err := conf.Check(f.Name.Name, fset, []*ast.File{f}, info) if err != nil { return nil, err } diff --git a/go/types/errors.go b/go/types/errors.go index 888361e63e0..7c63653dbff 100644 --- a/go/types/errors.go +++ b/go/types/errors.go @@ -327,7 +327,17 @@ func writeType(buf *bytes.Buffer, typ Type) { // if we are referring to a type that was imported; // but not when we are at the "top". We don't have // this information easily available here. - buf.WriteString(obj.pkg.name) + // + // TODO(gri): define variants of Type.String() + // and Object.String() that accept the referring *Package + // as a parameter and omit the package qualification for + // intra-package references to named types. + // + // Some applications may want another variant that accepts a + // file Scope and prints packages using that file's local + // import names. (Printing just pkg.name may be ambiguous + // or incorrect in other scopes.) + buf.WriteString(obj.pkg.path) buf.WriteByte('.') } s = t.obj.name