diff options
author | Robert Griesemer <gri@golang.org> | 2021-10-06 09:33:55 -0700 |
---|---|---|
committer | Michael Knyszek <mknyszek@google.com> | 2021-12-01 23:34:46 +0000 |
commit | 66007e5cfc9e151485791d440b7e67d44af1b29f (patch) | |
tree | 763d05fb8a9e6edb0638829003a480d9b3342280 | |
parent | 3c50f2739136bb4a6ff529c6ec975723a047a741 (diff) | |
download | go-66007e5cfc9e151485791d440b7e67d44af1b29f.tar.gz go-66007e5cfc9e151485791d440b7e67d44af1b29f.zip |
[release-branch.go1.17] go/types: break cycles in invalid types
This is a partial port of CL 354329 from types2 to go/types.
It contains an adjustment to type.go to deal with possibly
invalid type bounds.
Fixes #48825.
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>
Reviewed-on: https://go-review.googlesource.com/c/go/+/368456
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
-rw-r--r-- | src/go/types/decl.go | 1 | ||||
-rw-r--r-- | src/go/types/testdata/fixedbugs/issue48819.src | 15 | ||||
-rw-r--r-- | src/go/types/type.go | 3 |
3 files changed, 19 insertions, 0 deletions
diff --git a/src/go/types/decl.go b/src/go/types/decl.go index 9211febc6d..ec173ad1cc 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -343,6 +343,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 } } diff --git a/src/go/types/testdata/fixedbugs/issue48819.src b/src/go/types/testdata/fixedbugs/issue48819.src new file mode 100644 index 0000000000..9262110ea0 --- /dev/null +++ b/src/go/types/testdata/fixedbugs/issue48819.src @@ -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 +} diff --git a/src/go/types/type.go b/src/go/types/type.go index 2660ce4408..20c4bec0bc 100644 --- a/src/go/types/type.go +++ b/src/go/types/type.go @@ -759,6 +759,9 @@ func (check *Checker) newTypeParam(obj *TypeName, index int, bound Type) *_TypeP func (t *_TypeParam) Bound() *Interface { iface := asInterface(t.bound) + if iface == nil { + return &emptyInterface + } // use the type bound position if we have one pos := token.NoPos if n, _ := t.bound.(*Named); n != nil { |