1
0
mirror of https://github.com/golang/go synced 2024-11-17 12:54:47 -07:00

go/types: break cycles in invalid types

This is a clean port of CL 354329 from types2 to go/types.

For #48819.

Change-Id: I9efdcdbfa6432f3cee64d924a4c67ecc6793cf86
Reviewed-on: https://go-review.googlesource.com/c/go/+/354349
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2021-10-06 09:33:55 -07:00
parent 9062a5298b
commit 39a4df4967
4 changed files with 18 additions and 2 deletions

View File

@ -356,6 +356,7 @@ func (check *Checker) validType(typ Type, path []Object) typeInfo {
if tn == t.obj {
check.cycleError(path[i:])
t.info = invalid
t.underlying = Typ[Invalid]
return t.info
}
}

View File

@ -12,7 +12,7 @@ type Nat /* ERROR cycle */ interface {
type Zero struct{}
type Succ struct{
Nat /* ERROR interface contains type constraints */
Nat // Nat contains type constraints but is invalid, so no error
}
// Struct tests.

View File

@ -0,0 +1,15 @@
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package p
import "unsafe"
type T /* ERROR illegal cycle in declaration of T */ struct {
T
}
func _(t T) {
_ = unsafe.Sizeof(t) // should not go into infinite recursion here
}

View File

@ -292,7 +292,7 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T
// Union parsing reports a (delayed) error, so we can ignore this entry.
continue
default:
if typ == Typ[Invalid] {
if u == Typ[Invalid] {
continue
}
if check != nil && !check.allowVersion(check.pkg, 1, 18) {