@@ -225,8 +225,8 @@ func (check *Checker) validCycle(obj Object) (valid bool) {
225225 start := obj .color () - grey // index of obj in objPath
226226 cycle := check .objPath [start :]
227227 tparCycle := false // if set, the cycle is through a type parameter list
228- nval := 0 // number of (constant or variable) values in the cycle; valid if !generic
229- ndef := 0 // number of type definitions in the cycle; valid if !generic
228+ nval := 0 // number of (constant or variable) values in the cycle
229+ ndef := 0 // number of type definitions in the cycle
230230loop:
231231 for _ , obj := range cycle {
232232 switch obj := obj .(type ) {
@@ -235,7 +235,7 @@ loop:
235235 case * TypeName :
236236 // If we reach a generic type that is part of a cycle
237237 // and we are in a type parameter list, we have a cycle
238- // through a type parameter list, which is invalid .
238+ // through a type parameter list.
239239 if check .inTParamList && isGeneric (obj .typ ) {
240240 tparCycle = true
241241 break loop
@@ -286,25 +286,22 @@ loop:
286286 }()
287287 }
288288
289- if ! tparCycle {
290- // A cycle involving only constants and variables is invalid but we
291- // ignore them here because they are reported via the initialization
292- // cycle check.
293- if nval == len (cycle ) {
294- return true
295- }
289+ // Cycles through type parameter lists are ok (go.dev/issue/68162).
290+ if tparCycle {
291+ return true
292+ }
296293
297- // A cycle involving only types (and possibly functions) must have at least
298- // one type definition to be permitted: If there is no type definition, we
299- // have a sequence of alias type names which will expand ad infinitum.
300- if nval == 0 && ndef > 0 {
301- return true
302- }
294+ // A cycle involving only constants and variables is invalid but we
295+ // ignore them here because they are reported via the initialization
296+ // cycle check.
297+ if nval == len (cycle ) {
298+ return true
303299 }
304300
305- // Cycles through type parameter lists are ok (go.dev/issue/68162).
306- // TODO(gri) if we are happy with this this, remove this flag and simplify code.
307- if tparCycle {
301+ // A cycle involving only types (and possibly functions) must have at least
302+ // one type definition to be permitted: If there is no type definition, we
303+ // have a sequence of alias type names which will expand ad infinitum.
304+ if nval == 0 && ndef > 0 {
308305 return true
309306 }
310307
0 commit comments