diff --git a/src/cmd/compile/internal/types2/decl.go b/src/cmd/compile/internal/types2/decl.go index 7ae980e5c9..5fa1ca889f 100644 --- a/src/cmd/compile/internal/types2/decl.go +++ b/src/cmd/compile/internal/types2/decl.go @@ -358,6 +358,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/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2 b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2 index cef24bd237..7f55ba85a6 100644 --- a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2 +++ b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2 @@ -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. diff --git a/src/cmd/compile/internal/types2/testdata/fixedbugs/issue48819.src b/src/cmd/compile/internal/types2/testdata/fixedbugs/issue48819.src new file mode 100644 index 0000000000..9262110ea0 --- /dev/null +++ b/src/cmd/compile/internal/types2/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/cmd/compile/internal/types2/typeset.go b/src/cmd/compile/internal/types2/typeset.go index 37030b2ca1..8eb43a27e5 100644 --- a/src/cmd/compile/internal/types2/typeset.go +++ b/src/cmd/compile/internal/types2/typeset.go @@ -294,7 +294,7 @@ func computeInterfaceTypeSet(check *Checker, pos syntax.Pos, ityp *Interface) *_ // 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) {