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

x/tools/go/types: need a generalization of the Type.String method and TypeString function #11133

Closed
adonovan opened this issue Jun 9, 2015 · 2 comments

Comments

@adonovan
Copy link
Member

adonovan commented Jun 9, 2015

The Type.String method and TypeString function are thin wrappers around a complex set of pretty-printing functions. Object.String and ObjectString are part of the same strongly connected component.

These functions are useful, but some clients need variants that differ in their treatment of named types. For example, when printing results about a particular place in a program, it's best to use the locally appropriate name for each imported package, as determined by the ast.File Scope.

If we changed TypeString and ObjectString so that they accept a func(*Named)string parameter that formats the named types, then all three of these variants could be easily expressed, and any future ones too.

@gopherbot
Copy link
Contributor

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

@gopherbot
Copy link
Contributor

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

@mikioh mikioh changed the title go/types: need a generalization of the Type.String method and TypeString function x/tools/go/types: need a generalization of the Type.String method and TypeString function Jun 30, 2015
alandonovan pushed a commit that referenced this issue Jun 30, 2015
…function

The optional Qualifier function determines what prefix to attach to
package-level names, enabling clients to qualify packages in different
ways, for example, using only the package name instead of its complete
path, or using the locally appropriate name for package given a set of
(possibly renaming) imports.

Prior to this change, clients wanting this behavior had to copy
hundreds of lines of complex printing logic.

Fun fact: (*types.Package).Path and (*types.Package).Name are valid
Qualifier functions.

We provide the RelativeTo helper function to create Qualifiers so that
the old behavior remains a one-liner.

Fixes #11133

This CL is a copy of https://go-review.googlesource.com/#/c/11692/
to the golang.org/x/tools repository.

Change-Id: I26d0f3644d077a26bfe350989f9c545f018eefbf
Reviewed-on: https://go-review.googlesource.com/11790
Reviewed-by: Robert Griesemer <[email protected]>
Run-TryBot: Robert Griesemer <[email protected]>
@golang golang locked and limited conversation to collaborators Jun 29, 2016
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

2 participants