go/types, types2: remove InvalidTypeCycle from literals.go

Both CL 722161 and CL 724140 implement a more general solution to
detecting cycles involving values of a type on the object path.

The logic in literals.go was intended to be a stop-gap solution and
is no longer necessary.

Change-Id: I328c0febf35444f07fc1894278dc76ab140710bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/724380
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Mark Freeman <markfreeman@google.com>
This commit is contained in:
Mark Freeman 2025-11-25 13:56:18 -05:00 committed by Gopher Robot
parent ff2fd6327e
commit c048a9a11f
2 changed files with 0 additions and 58 deletions

View file

@ -145,13 +145,6 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
switch u, _ := commonUnder(base, nil); utyp := u.(type) {
case *Struct:
// Prevent crash if the struct referred to is not yet set up.
// See analogous comment for *Array.
if utyp.fields == nil {
check.error(e, InvalidTypeCycle, "invalid recursive type")
x.mode = invalid
return
}
if len(e.ElemList) == 0 {
break
}
@ -225,14 +218,6 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
}
case *Array:
// Prevent crash if the array referred to is not yet set up. Was go.dev/issue/18643.
// This is a stop-gap solution. Should use Checker.objPath to report entire
// path starting with earliest declaration in the source. TODO(gri) fix this.
if utyp.elem == nil {
check.error(e, InvalidTypeCycle, "invalid recursive type")
x.mode = invalid
return
}
n := check.indexedElts(e.ElemList, utyp.elem, utyp.len)
// If we have an array of unknown length (usually [...]T arrays, but also
// arrays [n]T where n is invalid) set the length now that we know it and
@ -254,23 +239,9 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
}
case *Slice:
// Prevent crash if the slice referred to is not yet set up.
// See analogous comment for *Array.
if utyp.elem == nil {
check.error(e, InvalidTypeCycle, "invalid recursive type")
x.mode = invalid
return
}
check.indexedElts(e.ElemList, utyp.elem, -1)
case *Map:
// Prevent crash if the map referred to is not yet set up.
// See analogous comment for *Array.
if utyp.key == nil || utyp.elem == nil {
check.error(e, InvalidTypeCycle, "invalid recursive type")
x.mode = invalid
return
}
// If the map key type is an interface (but not a type parameter),
// the type of a constant key must be considered when checking for
// duplicates.

View file

@ -149,13 +149,6 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
switch u, _ := commonUnder(base, nil); utyp := u.(type) {
case *Struct:
// Prevent crash if the struct referred to is not yet set up.
// See analogous comment for *Array.
if utyp.fields == nil {
check.error(e, InvalidTypeCycle, "invalid recursive type")
x.mode = invalid
return
}
if len(e.Elts) == 0 {
break
}
@ -229,14 +222,6 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
}
case *Array:
// Prevent crash if the array referred to is not yet set up. Was go.dev/issue/18643.
// This is a stop-gap solution. Should use Checker.objPath to report entire
// path starting with earliest declaration in the source. TODO(gri) fix this.
if utyp.elem == nil {
check.error(e, InvalidTypeCycle, "invalid recursive type")
x.mode = invalid
return
}
n := check.indexedElts(e.Elts, utyp.elem, utyp.len)
// If we have an array of unknown length (usually [...]T arrays, but also
// arrays [n]T where n is invalid) set the length now that we know it and
@ -258,23 +243,9 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
}
case *Slice:
// Prevent crash if the slice referred to is not yet set up.
// See analogous comment for *Array.
if utyp.elem == nil {
check.error(e, InvalidTypeCycle, "invalid recursive type")
x.mode = invalid
return
}
check.indexedElts(e.Elts, utyp.elem, -1)
case *Map:
// Prevent crash if the map referred to is not yet set up.
// See analogous comment for *Array.
if utyp.key == nil || utyp.elem == nil {
check.error(e, InvalidTypeCycle, "invalid recursive type")
x.mode = invalid
return
}
// If the map key type is an interface (but not a type parameter),
// the type of a constant key must be considered when checking for
// duplicates.