]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: break cycles in invalid types
authorRobert Griesemer <gri@golang.org>
Wed, 6 Oct 2021 16:33:55 +0000 (09:33 -0700)
committerRobert Griesemer <gri@golang.org>
Wed, 6 Oct 2021 19:44:14 +0000 (19:44 +0000)
This is a clean port of CL 354329 from types2 to go/types.

For #48819.

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

index 3c68bbfb20e4b7a661fc2874ed69fc0a327cdb93..22202cc7c99362166138ca982ba6dd888bbd602b 100644 (file)
@@ -356,6 +356,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 ac336a2eceb09b7f522ae34285f3c8404ab7d36e..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/go/types/testdata/fixedbugs/issue48819.src b/src/go/types/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 b4477998628631d252486111e04e21ba31fb6d14..a1893d0588fc573f9bbda5f4b273199b881a7978 100644 (file)
@@ -292,7 +292,7 @@ func computeInterfaceTypeSet(check *Checker, pos token.Pos, ityp *Interface) *_T
                        // 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) {