From: Robert Griesemer Date: Wed, 6 Oct 2021 16:33:55 +0000 (-0700) Subject: [release-branch.go1.17] go/types: break cycles in invalid types X-Git-Tag: go1.17.4~3 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=66007e5cfc9e151485791d440b7e67d44af1b29f;p=gostls13.git [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 Reviewed-by: Robert Findley Reviewed-on: https://go-review.googlesource.com/c/go/+/368456 Run-TryBot: Robert Griesemer TryBot-Result: Go Bot --- 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 {