You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When go/types encounters an embedded (unnamed) field, it uses the Pos of the ast.Field syntax node as the Pos of the field types.Var object. If the field type is a qualified identifier p.T, this means that the source code at the position of the declaration of struct field T does not contain an identifier "T". Instead, the source at that position is the package identifier "p".
I realize these invariants are not as well formalized as we would like, but I argue this is a bug. It should use the Pos of the type name identifier in all cases.
The relevant source is in go/types/struct.go, Checker.structType:
func (check *Checker) structType(styp *Struct, e *ast.StructType) {
...
for _, f := range list.List {
typ = check.varType(f.Type)
tag = check.tag(f.Tag)
if len(f.Names) > 0 {
// named fields
...
} else {
// embedded field
// spec: "An embedded type 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."
pos := f.Type.Pos() // <--------------HERE
The text was updated successfully, but these errors were encountered:
This change adds a regression test for bug in gopls' references
operation applied to the T identifier in an embedded struct field
such as struct{p.T): instead of reporting references to T,
it reports references to package name p.
This is a consequence of go/types bug golang/go#60372,
which sets the position of the struct field types.Var to
that of the ast.Field syntax (p) not the type name (T).
The bug was fixed in go1.21.
Updates golang/go#60372Fixesgolang/go#60369
Change-Id: Ibabe885ea689b30d966dbf7e51f8c25e44a6ce1c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/497495
gopls-CI: kokoro <[email protected]>
Run-TryBot: Alan Donovan <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
When go/types encounters an embedded (unnamed) field, it uses the Pos of the ast.Field syntax node as the Pos of the field types.Var object. If the field type is a qualified identifier p.T, this means that the source code at the position of the declaration of struct field T does not contain an identifier "T". Instead, the source at that position is the package identifier "p".
I realize these invariants are not as well formalized as we would like, but I argue this is a bug. It should use the Pos of the type name identifier in all cases.
The relevant source is in go/types/struct.go, Checker.structType:
The text was updated successfully, but these errors were encountered: