Skip to content

Commit 3765758

Browse files
author
Robert Griesemer
committed
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>
1 parent f6b9d56 commit 3765758

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

src/cmd/compile/internal/types2/decl.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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
230230
loop:
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

src/go/types/decl.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,8 +226,8 @@ func (check *Checker) validCycle(obj Object) (valid bool) {
226226
start := obj.color() - grey // index of obj in objPath
227227
cycle := check.objPath[start:]
228228
tparCycle := false // if set, the cycle is through a type parameter list
229-
nval := 0 // number of (constant or variable) values in the cycle; valid if !generic
230-
ndef := 0 // number of type definitions in the cycle; valid if !generic
229+
nval := 0 // number of (constant or variable) values in the cycle
230+
ndef := 0 // number of type definitions in the cycle
231231
loop:
232232
for _, obj := range cycle {
233233
switch obj := obj.(type) {
@@ -236,7 +236,7 @@ loop:
236236
case *TypeName:
237237
// If we reach a generic type that is part of a cycle
238238
// and we are in a type parameter list, we have a cycle
239-
// through a type parameter list, which is invalid.
239+
// through a type parameter list.
240240
if check.inTParamList && isGeneric(obj.typ) {
241241
tparCycle = true
242242
break loop
@@ -287,25 +287,22 @@ loop:
287287
}()
288288
}
289289

290-
if !tparCycle {
291-
// A cycle involving only constants and variables is invalid but we
292-
// ignore them here because they are reported via the initialization
293-
// cycle check.
294-
if nval == len(cycle) {
295-
return true
296-
}
290+
// Cycles through type parameter lists are ok (go.dev/issue/68162).
291+
if tparCycle {
292+
return true
293+
}
297294

298-
// A cycle involving only types (and possibly functions) must have at least
299-
// one type definition to be permitted: If there is no type definition, we
300-
// have a sequence of alias type names which will expand ad infinitum.
301-
if nval == 0 && ndef > 0 {
302-
return true
303-
}
295+
// A cycle involving only constants and variables is invalid but we
296+
// ignore them here because they are reported via the initialization
297+
// cycle check.
298+
if nval == len(cycle) {
299+
return true
304300
}
305301

306-
// Cycles through type parameter lists are ok (go.dev/issue/68162).
307-
// TODO(gri) if we are happy with this this, remove this flag and simplify code.
308-
if tparCycle {
302+
// A cycle involving only types (and possibly functions) must have at least
303+
// one type definition to be permitted: If there is no type definition, we
304+
// have a sequence of alias type names which will expand ad infinitum.
305+
if nval == 0 && ndef > 0 {
309306
return true
310307
}
311308

0 commit comments

Comments
 (0)