aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/go/types/decl.go1
-rw-r--r--src/go/types/testdata/fixedbugs/issue48819.src15
-rw-r--r--src/go/types/type.go3
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 {