Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go/types: PkgName.Pkg() is inconsistent and lossy #8628

adonovan opened this issue Sep 2, 2014 · 2 comments

go/types: PkgName.Pkg() is inconsistent and lossy #8628

adonovan opened this issue Sep 2, 2014 · 2 comments


Copy link

adonovan commented Sep 2, 2014

The Pkg() methods of all implementations of types.Object (named entities) return the
package that declared that entity... except one.  PkgName's Pkg method returns the
object that is imported.  For example:

package main
import foo "fmt"
var _ foo.Stringer

The object 'foo' is a PkgName, whose Pkg() returns not "main" but
"fmt".  This is lossy, since it's impossible to get from foo to
"main" via the API, and inconsistent with all other objects, making it much
harder for clients to use.  (Essentially, they must pass around a pair of (*Package,
Object) in lieu of Object because the Pkg() method is not to be trusted.)

I think PkgName should have a new method, ImportedPackage() that returns the package
that was imported, as distinct from the importing package that logically contains the

(go/ssa and oracle will need to be audited, among others.  If you send me a CL for
go/types, I'll take care of the rest.)
Copy link

Comment 1:

CL mentions this issue.

Copy link
Member Author

adonovan commented Sep 2, 2014

Comment 2:

This issue was closed by revision golang/tools@95bd0c4.

Status changed to Fixed.

@adonovan adonovan added the fixed label Sep 2, 2014
@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

3 participants