]> Cypherpunks repositories - gostls13.git/commitdiff
go/types, types2: clarify docs for resolveUnderlying
authorMark Freeman <mark@golang.org>
Thu, 23 Oct 2025 20:25:28 +0000 (16:25 -0400)
committerGopher Robot <gobot@golang.org>
Mon, 27 Oct 2025 18:47:41 +0000 (11:47 -0700)
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>

src/cmd/compile/internal/types2/named.go
src/go/types/named.go

index e451defce6d688dba5930e13556512377f364202..06f4e75c82d38e9a3eb989493e940e4d85404d05 100644 (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.
-//
-// 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
                }
        }
 
index e49bdc966663135250df2bc5d7529e8f0e8e322c..130919435a171d2df8609a2a3fd2b2408c5bcfac 100644 (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.
-//
-// 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
                }
        }