src/go/types/decl.go | 1 + src/go/types/testdata/fixedbugs/issue48819.src | 15 +++++++++++++++ src/go/types/type.go | 3 +++ diff --git a/src/go/types/decl.go b/src/go/types/decl.go index 9211febc6da1620a43e9867af2f37c149a6f0753..ec173ad1ccc9cb62ed3ae292ae303e5e1f23c057 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -343,6 +343,7 @@ } 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 0000000000000000000000000000000000000000..9262110ea09e71e96c3494186beaba6c6c5f4db5 --- /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 2660ce4408c1b640f67bf517ca72d3819055907e..20c4bec0bce241ac84fae75a309f90e81948f1e6 100644 --- a/src/go/types/type.go +++ b/src/go/types/type.go @@ -759,6 +759,9 @@ } 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 {