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: API: rename LookupFieldOrMethod to Select (or something select-y) #10091

Closed
alandonovan opened this issue Mar 5, 2015 · 5 comments
Closed
Milestone

Comments

@alandonovan
Copy link
Contributor

LookupFieldOrMethod returns essentially the same information as a types.Selection, given the information present in a typed ast.SelectorExpr. It would be nice if its type and its name related it to selections. Perhaps something like this:

// Select resolves a selection whose operand type is T and whose
// selector is (pkg, name). Addressable indicates that the operand is a variable of type T.
func Select(T Type, addressable bool, pkg *Package, name string) types.Selection

@alandonovan
Copy link
Contributor Author

Perhaps also explain that Select(*T, false, ...) is not equivalent to Select(T, true, ...) since the former selects only methods whose receiver is *T but the latter may select a method whose receiver is T or *T.

@rsc rsc added this to the Go1.5 milestone Apr 10, 2015
@griesemer
Copy link
Contributor

Unfortunate. API is frozen.

@adonovan
Copy link
Member

While you were travelling, Russ explicitly exempted API cleanups to go/types from the freeze since they would not break any existing packages, and this one is less disruptive than both the Scope-to-Block renaming I proposed and the MethodSet move you proposed.

Please re-open this ticket.

@alandonovan alandonovan reopened this Oct 8, 2015
@alandonovan
Copy link
Contributor Author

Even though we can't rename the existing LookupFieldOrMethod, there's still a gap in the API.

Consider (*ssa.Program).MethodValue(sel *types.Selection) *ssa.Function. It requires a *types.Selection as its argument. If you have the receiver type T and the selector name (pkg, name), you can obtain a Selection by calling types.NewMethodSet(T).Lookup(pkg, name), but this is asymptotically more expensive than calling types.LookupFieldOrMethod(T, false, pkg, name).

Ideally the client would be able to call LookupFieldOrMethod and then construct a Selection (field or method) from the result, but there is no way for clients to construct a Selection.

Could we expose a NewSelection constructor?

@griesemer
Copy link
Contributor

Closed in favor of new issue #12881.

@golang golang locked and limited conversation to collaborators Oct 9, 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

5 participants