Skip to content

Commit 5b305e1

Browse files
committed
[dev.go2go] go/types: avoid endless recursion in self-recursive newtype declarations.
Updates #39634. Fixes #40037.
1 parent 34f7622 commit 5b305e1

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

src/go/types/check_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ var tests = [][]string{
140140
{"fixedbugs/issue39948.go2"},
141141
{"fixedbugs/issue39976.go2"},
142142
{"fixedbugs/issue39982.go2"},
143+
{"fixedbugs/issue40037.go2"},
143144
}
144145

145146
var fset = token.NewFileSet()

src/go/types/fixedbugs/issue40037.go2

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package main
2+
3+
// from issue #40037
4+
type comp(type T comparable) T
5+
type K /* ERROR illegal cycle */ comp(K) // becomes 'type K K', where K is comparable
6+
7+
// from issue #39634 crash 22
8+
type T(type _ interface{ a() }) int
9+
type A(type P) T(A(int))
10+

src/go/types/subst.go

+8
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ func (check *Checker) instantiate(pos token.Pos, typ Type, targs []Type, poslist
142142
// - check only if we have methods
143143
check.completeInterface(token.NoPos, iface)
144144
if len(iface.allMethods) > 0 {
145+
// Break cycle in cases like
146+
//
147+
// type constr(type T comparable) T
148+
// type K constr(K)
149+
if t1 := typ.Named(); t1 != nil && t1.underlying == t1.orig {
150+
break
151+
}
152+
145153
// If the type argument is a type parameter itself, its pointer designation
146154
// must match the pointer designation of the callee's type parameter.
147155
// If the type argument is a pointer to a type parameter, the type argument's

0 commit comments

Comments
 (0)