go/types, types2: clarify docs for resolveUnderlying

The resolveUnderlying method only detects cycles among type names, where
no type literal or predeclared type can be found (which would yield an
underlying type).

Change-Id: I203f3856eaf63a8a9d317c22521755390f9c1023
Reviewed-on: https://go-review.googlesource.com/c/go/+/714402
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Mark Freeman 2025-10-23 16:25:28 -04:00 committed by Gopher Robot
parent d8a32f3d4b
commit 180c07e2c1
2 changed files with 16 additions and 18 deletions

View file

@ -607,15 +607,14 @@ func (t *Named) String() string { return TypeString(t, nil) }
// resolveUnderlying computes the underlying type of n.
//
// It does so by following RHS type chains. If a type literal is found, each
// named type in the chain has its underlying set to that type. Aliases are
// skipped because their underlying type is not memoized.
// It does so by following RHS type chains for alias and named types. If any
// other type T is found, each named type in the chain has its underlying
// type set to T. Aliases are skipped because their underlying type is
// not memoized.
//
// This function also checks for instantiated layout cycles, which are
// reachable only in the case where unpack() expanded an instantiated
// type which became self-referencing without indirection.
// If such a cycle is found, the underlying type is set to Typ[Invalid]
// and a cycle is reported.
// This method also checks for cycles among alias and named types, which will
// yield no underlying type. If such a cycle is found, the underlying type is
// set to Typ[Invalid] and a cycle is reported.
func (n *Named) resolveUnderlying() {
assert(n.stateHas(unpacked))
@ -663,7 +662,7 @@ func (n *Named) resolveUnderlying() {
rhs = t.rhs()
default:
u = rhs // any type literal works
u = rhs // any type literal or predeclared type works
}
}

View file

@ -610,15 +610,14 @@ func (t *Named) String() string { return TypeString(t, nil) }
// resolveUnderlying computes the underlying type of n.
//
// It does so by following RHS type chains. If a type literal is found, each
// named type in the chain has its underlying set to that type. Aliases are
// skipped because their underlying type is not memoized.
// It does so by following RHS type chains for alias and named types. If any
// other type T is found, each named type in the chain has its underlying
// type set to T. Aliases are skipped because their underlying type is
// not memoized.
//
// This function also checks for instantiated layout cycles, which are
// reachable only in the case where unpack() expanded an instantiated
// type which became self-referencing without indirection.
// If such a cycle is found, the underlying type is set to Typ[Invalid]
// and a cycle is reported.
// This method also checks for cycles among alias and named types, which will
// yield no underlying type. If such a cycle is found, the underlying type is
// set to Typ[Invalid] and a cycle is reported.
func (n *Named) resolveUnderlying() {
assert(n.stateHas(unpacked))
@ -666,7 +665,7 @@ func (n *Named) resolveUnderlying() {
rhs = t.rhs()
default:
u = rhs // any type literal works
u = rhs // any type literal or predeclared type works
}
}