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

Closed
adonovan opened this issue Sep 2, 2014 · 2 comments
Closed

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

adonovan opened this issue Sep 2, 2014 · 2 comments

Comments

@adonovan
Copy link
Member

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
identifier.

(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.)
@gopherbot
Copy link

Comment 1:

CL https://golang.org/cl/136090043 mentions this issue.

@adonovan
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.
Projects
None yet
Development

No branches or pull requests

3 participants