]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: break cycles in invalid types
authorRobert Griesemer <gri@golang.org>
Wed, 6 Oct 2021 16:03:34 +0000 (09:03 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 6 Oct 2021 19:44:11 +0000 (19:44 +0000)
This CL reverses the change in CL 284254 (which was ported
to types2) which originated in CL 240901 to address a crash
in a test created by a fuzzer (that crash appears to be
avoided in other ways, now).

This exposed another bug in typeset.go where we don't look
for the underlying type when testing if a type is an interface
or not. Fixed that as well.

Adjusted a test case that now doesn't report an error anymore
(which is good).

Fixes #48819.

Change-Id: I611d68e053d6b8a2f7176d0cd5a44da2df28ad21
Reviewed-on: https://go-review.googlesource.com/c/go/+/354329
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue41124.go2
src/cmd/compile/internal/types2/testdata/fixedbugs/issue48819.src [new file with mode: 0644]
src/cmd/compile/internal/types2/typeset.go

index 7ae980e5c94c941cbbbc61e21ede5194b1dab041..5fa1ca889f5fec11ce52ad35e86ecd48e6c683fe 100644 (file)
@@ -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
                                }
                        }
index cef24bd237959f3befde6c55e5f01145c2e03cc6..7f55ba85a6b42d4580a030337e5bba3e1da71713 100644 (file)
@@ -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 (file)
index 0000000..9262110
--- /dev/null
@@ -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
+}
index 37030b2ca16df0fd6971a4e720ef4a7de7da579b..8eb43a27e59f8a13f60bbec00749aac3f04fc2f4 100644 (file)
@@ -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) {