From 180c07e2c12779872d6cf907b291e4c0b66f93a1 Mon Sep 17 00:00:00 2001 From: Mark Freeman Date: Thu, 23 Oct 2025 16:25:28 -0400 Subject: [PATCH] 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 Auto-Submit: Mark Freeman LUCI-TryBot-Result: Go LUCI --- src/cmd/compile/internal/types2/named.go | 19 +++++++++---------- src/go/types/named.go | 19 +++++++++---------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/cmd/compile/internal/types2/named.go b/src/cmd/compile/internal/types2/named.go index e451defce6..06f4e75c82 100644 --- a/src/cmd/compile/internal/types2/named.go +++ b/src/cmd/compile/internal/types2/named.go @@ -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. -// -// 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. +// 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 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 } } diff --git a/src/go/types/named.go b/src/go/types/named.go index e49bdc9666..130919435a 100644 --- a/src/go/types/named.go +++ b/src/go/types/named.go @@ -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. -// -// 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. +// 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 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 } } -- 2.52.0