golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.92k stars 17.65k forks source link

spec: incorrect requirement for the embedded field #69460

Closed leabit closed 1 month ago

leabit commented 1 month ago

What is the URL of the page with the issue?

https://go.dev/ref/spec#Struct_types

What is your user agent?

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Screenshot

No response

What did you do?

I came across a discussion about the incorrect terminology used in the specification when referring to promoted methods of the alias to unnamed type, and the changes that were made to address this issue. However, there remains another related problem, and I believe its resolution should also be considered as part of the overall solution. The specification states the following:

An embedded field must be specified as a type name T or as a pointer to a non-interface type name *T, and T itself may not be a pointer type.

If the type name denotes only defined types everything would be fine, however, it also denotes type alias to the unnamed (undefined) types.

What did you see happen?

So according to the specification, the following code is invalid since type name T is a pointer type:

package main

type T = *int

type S struct {
    T
}

func main() {}

However, it compiles.

What did you expect to see?

To not compile (actually to compile, but to correct the specification to properly address this as well).

gabyhelp commented 1 month ago

Related Issues and Documentation

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

leabit commented 1 month ago

Al right, it looks like the same issue was already mentioned in #22005, however, nothing has been done for 7 years

seankhliao commented 1 month ago

Duplicate of #22005