go/types, types2: minor cleanup (remove TODO)

Follow-up to CL 711420.

Change-Id: If577e96f413e46b98dd86d11605de1004637851a
Reviewed-on: https://go-review.googlesource.com/c/go/+/711540
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Robert Griesemer 2025-10-13 15:55:04 -07:00
parent f6b9d56aff
commit 3765758b96
2 changed files with 34 additions and 40 deletions

View file

@ -225,8 +225,8 @@ func (check *Checker) validCycle(obj Object) (valid bool) {
start := obj.color() - grey // index of obj in objPath
cycle := check.objPath[start:]
tparCycle := false // if set, the cycle is through a type parameter list
nval := 0 // number of (constant or variable) values in the cycle; valid if !generic
ndef := 0 // number of type definitions in the cycle; valid if !generic
nval := 0 // number of (constant or variable) values in the cycle
ndef := 0 // number of type definitions in the cycle
loop:
for _, obj := range cycle {
switch obj := obj.(type) {
@ -235,7 +235,7 @@ loop:
case *TypeName:
// If we reach a generic type that is part of a cycle
// and we are in a type parameter list, we have a cycle
// through a type parameter list, which is invalid.
// through a type parameter list.
if check.inTParamList && isGeneric(obj.typ) {
tparCycle = true
break loop
@ -286,25 +286,22 @@ loop:
}()
}
if !tparCycle {
// A cycle involving only constants and variables is invalid but we
// ignore them here because they are reported via the initialization
// cycle check.
if nval == len(cycle) {
return true
}
// A cycle involving only types (and possibly functions) must have at least
// one type definition to be permitted: If there is no type definition, we
// have a sequence of alias type names which will expand ad infinitum.
if nval == 0 && ndef > 0 {
return true
}
// Cycles through type parameter lists are ok (go.dev/issue/68162).
if tparCycle {
return true
}
// Cycles through type parameter lists are ok (go.dev/issue/68162).
// TODO(gri) if we are happy with this this, remove this flag and simplify code.
if tparCycle {
// A cycle involving only constants and variables is invalid but we
// ignore them here because they are reported via the initialization
// cycle check.
if nval == len(cycle) {
return true
}
// A cycle involving only types (and possibly functions) must have at least
// one type definition to be permitted: If there is no type definition, we
// have a sequence of alias type names which will expand ad infinitum.
if nval == 0 && ndef > 0 {
return true
}

View file

@ -226,8 +226,8 @@ func (check *Checker) validCycle(obj Object) (valid bool) {
start := obj.color() - grey // index of obj in objPath
cycle := check.objPath[start:]
tparCycle := false // if set, the cycle is through a type parameter list
nval := 0 // number of (constant or variable) values in the cycle; valid if !generic
ndef := 0 // number of type definitions in the cycle; valid if !generic
nval := 0 // number of (constant or variable) values in the cycle
ndef := 0 // number of type definitions in the cycle
loop:
for _, obj := range cycle {
switch obj := obj.(type) {
@ -236,7 +236,7 @@ loop:
case *TypeName:
// If we reach a generic type that is part of a cycle
// and we are in a type parameter list, we have a cycle
// through a type parameter list, which is invalid.
// through a type parameter list.
if check.inTParamList && isGeneric(obj.typ) {
tparCycle = true
break loop
@ -287,25 +287,22 @@ loop:
}()
}
if !tparCycle {
// A cycle involving only constants and variables is invalid but we
// ignore them here because they are reported via the initialization
// cycle check.
if nval == len(cycle) {
return true
}
// A cycle involving only types (and possibly functions) must have at least
// one type definition to be permitted: If there is no type definition, we
// have a sequence of alias type names which will expand ad infinitum.
if nval == 0 && ndef > 0 {
return true
}
// Cycles through type parameter lists are ok (go.dev/issue/68162).
if tparCycle {
return true
}
// Cycles through type parameter lists are ok (go.dev/issue/68162).
// TODO(gri) if we are happy with this this, remove this flag and simplify code.
if tparCycle {
// A cycle involving only constants and variables is invalid but we
// ignore them here because they are reported via the initialization
// cycle check.
if nval == len(cycle) {
return true
}
// A cycle involving only types (and possibly functions) must have at least
// one type definition to be permitted: If there is no type definition, we
// have a sequence of alias type names which will expand ad infinitum.
if nval == 0 && ndef > 0 {
return true
}