-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: add Info.PkgName method #62037
Comments
Makes sense to me, in general, though I think we should discuss the name/signature. The proposed API is fine, but perhaps inconsistent with the existing methods. Currently, // ImportOf returns the local package name defined by the specified import, or nil if not found.
func (info *types.Info) ImportOf(imp *ast.ImportSpec) *types.PkgName |
Fair point about nil (vs bool). How about a name of PkgNameOf? |
|
I found at least 5 copies of this function in x/tools:
|
This proposal has been added to the active column of the proposals project |
Have all remaining concerns about this proposal been addressed? In go/types, add a new method:
|
For consistency in naming with the existing functions, and per the comment above, this should probably be: // PkgNameOf returns the local package name defined by the import,
// or nil if it is not found.
//
// Precondition: the Defs and Implicts maps are populated.
func (info *types.Info) PkgNameOf(imp *ast.ImportSpec) *PkgName |
Based on the discussion above, this proposal seems like a likely accept. In go/types, add a new method:
|
Change https://go.dev/cl/541575 mentions this issue: |
For #62037. Change-Id: I354f6417232708278d3f2b2d5ea41ff48e08d6b6 Reviewed-on: https://go-review.googlesource.com/c/go/+/541575 Reviewed-by: Alan Donovan <[email protected]> Reviewed-by: Robert Findley <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]>
The decl.go file in cmd/compile/internal/noder has been removed as its only contained function, pkgNameOf, is now redundant. This change updates the references of this function to use the method PkgNameOf directly from the *types2.Info struct. For golang#62037
Change https://go.dev/cl/541738 mentions this issue: |
Replace calls to pkgNameOf with calls to types2.Info.PkgNameOf. Delete function pkgNameOf and file decl.go which are not needed anymore. For #62037 Change-Id: Ib8a0411cc9eb9fdd42ee6e73c23deed2daaf73d5 GitHub-Last-Rev: 3c8928f GitHub-Pull-Request: #64075 Reviewed-on: https://go-review.googlesource.com/c/go/+/541738 TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Keith Randall <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> Run-TryBot: qiulaidongfeng <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Keith Randall <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
No change in consensus, so accepted. 🎉 In go/types, add a new method:
|
This has already been implemented and was submitted. Closing. |
Change https://go.dev/cl/546975 mentions this issue: |
For #62037. Change-Id: Id1d02f88205e5ea62662e78c8313731ec9e55b1e Reviewed-on: https://go-review.googlesource.com/c/go/+/546975 Reviewed-by: Alan Donovan <[email protected]> TryBot-Bypass: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]>
For golang#62037. Change-Id: Id1d02f88205e5ea62662e78c8313731ec9e55b1e Reviewed-on: https://go-review.googlesource.com/c/go/+/546975 Reviewed-by: Alan Donovan <[email protected]> TryBot-Bypass: Robert Griesemer <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> Auto-Submit: Robert Griesemer <[email protected]>
Any time a client of go/types needs to find the
types.PkgName
(or just the name) defined by an import, they must write logic equivalent to this:I propose that we add this method to
types.Info
.The text was updated successfully, but these errors were encountered: