-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: go/types: add HasTypeName interface #66890
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
Comments
Change https://go.dev/cl/604476 mentions this issue: |
Updates #65855 Updates #66890 Change-Id: I167c9de818049cae02f0d99f8e0fb4017e07bea9 Reviewed-on: https://go-review.googlesource.com/c/go/+/604476 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Griesemer <gri@google.com> Reviewed-by: Robert Findley <rfindley@google.com>
I note that we have an unexported function // hasName reports whether t has a name. This includes
// predeclared types, defined types, and type parameters.
// hasName may be called with types that are not fully set up.
func hasName(t Type) bool {
switch Unalias(t).(type) {
case *Basic, *Named, *TypeParam:
return true
}
return false
} Per the spec: "Predeclared types, defined types, and type parameters are called named types." Maybe the interface should just be called "HasName". Having the |
In the branch where I was playing with this I ended up using the name TypeWithName to make clear that the interface is a restriction of Type; otherwise it's a bit unclear what kind of thing it is. |
My 2 cents: |
In the spec, a named type has a very specific meaning; specifically, an alias type may not be a named type. This interface is about whether a type has an |
During the types.Alias work, there was a recurring need (7 times in x/tools; @findleyr is adding an eighth) for this interface:
Of course users can easily define it for themselves, but adding it to
go/types
provides a good place to hang additional documentation.Related:
@findleyr @griesemer
The text was updated successfully, but these errors were encountered: