From: Robert Griesemer Date: Mon, 13 Oct 2025 22:55:04 +0000 (-0700) Subject: go/types, types2: minor cleanup (remove TODO) X-Git-Tag: go1.26rc1~627 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3765758b96746e202bb52312d4b026085a0f25a1;p=gostls13.git 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 Reviewed-by: Mark Freeman LUCI-TryBot-Result: Go LUCI --- diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go index 3ff2426966..4ebd945407 100644 --- a/src/cmd/compile/internal/types2/decl.go +++ b/src/cmd/compile/internal/types2/decl.go @@ -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 - } + // Cycles through type parameter lists are ok (go.dev/issue/68162). + if tparCycle { + 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 - } + // 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 } - // 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 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 } diff --git a/src/go/types/decl.go b/src/go/types/decl.go index fcae1f9529..aef7f6ad0b 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -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 - } + // Cycles through type parameter lists are ok (go.dev/issue/68162). + if tparCycle { + 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 - } + // 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 } - // 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 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 }