mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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:
parent
ff2fd6327e
commit
c048a9a11f
2 changed files with 0 additions and 58 deletions
|
|
@ -145,13 +145,6 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
|
||||||
|
|
||||||
switch u, _ := commonUnder(base, nil); utyp := u.(type) {
|
switch u, _ := commonUnder(base, nil); utyp := u.(type) {
|
||||||
case *Struct:
|
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 {
|
if len(e.ElemList) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -225,14 +218,6 @@ func (check *Checker) compositeLit(x *operand, e *syntax.CompositeLit, hint Type
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Array:
|
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)
|
n := check.indexedElts(e.ElemList, utyp.elem, utyp.len)
|
||||||
// If we have an array of unknown length (usually [...]T arrays, but also
|
// 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
|
// 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:
|
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)
|
check.indexedElts(e.ElemList, utyp.elem, -1)
|
||||||
|
|
||||||
case *Map:
|
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),
|
// 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
|
// the type of a constant key must be considered when checking for
|
||||||
// duplicates.
|
// duplicates.
|
||||||
|
|
|
||||||
|
|
@ -149,13 +149,6 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
|
||||||
|
|
||||||
switch u, _ := commonUnder(base, nil); utyp := u.(type) {
|
switch u, _ := commonUnder(base, nil); utyp := u.(type) {
|
||||||
case *Struct:
|
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 {
|
if len(e.Elts) == 0 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
@ -229,14 +222,6 @@ func (check *Checker) compositeLit(x *operand, e *ast.CompositeLit, hint Type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
case *Array:
|
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)
|
n := check.indexedElts(e.Elts, utyp.elem, utyp.len)
|
||||||
// If we have an array of unknown length (usually [...]T arrays, but also
|
// 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
|
// 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:
|
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)
|
check.indexedElts(e.Elts, utyp.elem, -1)
|
||||||
|
|
||||||
case *Map:
|
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),
|
// 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
|
// the type of a constant key must be considered when checking for
|
||||||
// duplicates.
|
// duplicates.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue