-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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
spec: some wording need to be adjusted for embedding alias of pointer types #22005
Comments
btw, some wording for the receiver type requirements in the Method declarations may also need to be adjusted, as aliases of *T can also be used as receiver types. |
I think those are still correct. We still have named types (any type that has a name); it's just that it may be a defined or an alias type. The rules for embedding allow alias types. The rules for method receivers explicitly say that the receiver type must be defined in the same package. Is there anything specific that you believe needs to be fixed (and why)? |
Maybe my English understanding is not correct, for embeddable types, spec says
However, T can be a pointer type (as an alias) type T = *int
type S struct{
T // T is a pointer
} And for method receivers, type S struct{}
type T = S
type P = *S
func (T) f() {}
func (*T) g() {}
func (P) h() {} Maybe, mention that |
Hm, you have a point. I'll look into this. Thank you! |
...
I think this is implicit in the definition of an alias itself; i.e. that an alias is just that, an alias for a defined type (recursive definition), not a type in and of itself. So in your method examples the receiver types are: type S struct{}
type T = S
type P = *S
func (T) f() {} // S
func (*T) g() {} // *S
func (P) h() {} // *S it's just that we're using aliases to refer to those two types. Similarly with embedding: type T1 = *int
type S struct{
T1 // *int; T = int in spec terms (i.e. the "may not be a pointer type" bit)
} |
@myitcv yes, no problems on the mechanism here. It is just that some terminologies and some wording need to be clarified. For example, what is a named type? Can an alias be called a type? Is alias of a defined type can also be called defined type? etc. |
I feel some wording for the method documentations of the For example, the word "unnamed" may be better to change to "non-defined". |
Change https://golang.org/cl/112717 mentions this issue: |
…n 'anonymous' On the API level this is just an update of the documentation to match the current spec more closely. On the implementation side, this is a rename of various unexported names. For #22005. Change-Id: Ie5ae32f3b10f003805240efcceab3d0fd373cd51 Reviewed-on: https://go-review.googlesource.com/112717 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Are the following descriptions accurate?
|
@go101 I believe those descriptions are still accurate; by type name we do mean a name denoting a type (and it could be an alias). |
The above shown current description excludes the following type T = *int
type S struct{
T // T is a pointer
} |
Or the following one?
|
A question, why pointer types whose base types are pointer and interface types can't be embedded? |
@go101 Originally, we wanted to avoid situations such as **T embeddings, etc. There are also interactions with lookup of embedded fields and methods. You're right that there are certainly unanswered questions here, and possibly inconsistencies. I'd love to simplify this, as it is only going to get more complex if we have generics as well. Thanks for pointing out the inconsistencies. We will get to this eventually; but at the moment it is not a high priority. |
I think I got why pointer types whose base types are pointer and interface types can't be embedded. |
Just found my above description is not accurate. It missed the following highlighted case:
|
I just noticed that, gc and gccgo have different behaviors on this inaccuracy. package main
type P = *bool
type T struct {
P
}
func main() {} |
@go101 At first glance I think that is a gccgo bug. Want to file an issue for that? Thanks. |
Just FYI: go/types also accepts this code. |
Ping @griesemer . This just came up again in #69460, q.v. |
Now, the wording is
However aliases of *T can also be embedded.
The text was updated successfully, but these errors were encountered: