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
Assignees
Milestone

Comments

@alandonovan
Copy link
Contributor

@alandonovan alandonovan commented Mar 5, 2015

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

@alandonovan alandonovan commented Mar 5, 2015

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.

Loading

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

@griesemer griesemer commented May 14, 2015

Unfortunate. API is frozen.

Loading

@griesemer griesemer closed this May 14, 2015
@adonovan
Copy link
Contributor

@adonovan adonovan commented May 15, 2015

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.

Loading

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

@alandonovan alandonovan commented Oct 8, 2015

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?

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Oct 8, 2015

Closed in favor of new issue #12881.

Loading

@griesemer griesemer closed this Oct 8, 2015
@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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants