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
Comments
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. |
Unfortunate. API is frozen. |
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. |
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? |
Closed in favor of new issue #12881. |
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
The text was updated successfully, but these errors were encountered: