Skip to content

Commit 66007e5

Browse files
griesemermknyszek
authored andcommitted
[release-branch.go1.17] go/types: break cycles in invalid types
This is a partial port of CL 354329 from types2 to go/types. It contains an adjustment to type.go to deal with possibly invalid type bounds. Fixes #48825. For #48819. Change-Id: I9efdcdbfa6432f3cee64d924a4c67ecc6793cf86 Reviewed-on: https://go-review.googlesource.com/c/go/+/354349 Trust: Robert Griesemer <[email protected]> Reviewed-by: Robert Findley <[email protected]> Reviewed-on: https://go-review.googlesource.com/c/go/+/368456 Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Go Bot <[email protected]>
1 parent 3c50f27 commit 66007e5

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/go/types/decl.go

+1
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,7 @@ func (check *Checker) validType(typ Type, path []Object) typeInfo {
343343
if tn == t.obj {
344344
check.cycleError(path[i:])
345345
t.info = invalid
346+
t.underlying = Typ[Invalid]
346347
return t.info
347348
}
348349
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2021 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package p
6+
7+
import "unsafe"
8+
9+
type T /* ERROR illegal cycle in declaration of T */ struct {
10+
T
11+
}
12+
13+
func _(t T) {
14+
_ = unsafe.Sizeof(t) // should not go into infinite recursion here
15+
}

src/go/types/type.go

+3
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,9 @@ func (check *Checker) newTypeParam(obj *TypeName, index int, bound Type) *_TypeP
759759

760760
func (t *_TypeParam) Bound() *Interface {
761761
iface := asInterface(t.bound)
762+
if iface == nil {
763+
return &emptyInterface
764+
}
762765
// use the type bound position if we have one
763766
pos := token.NoPos
764767
if n, _ := t.bound.(*Named); n != nil {

0 commit comments

Comments
 (0)