Skip to content

[dev.go2go] go/types: avoid endless recursion in self-recursive newty… #40051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/go/types/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ var tests = [][]string{
{"fixedbugs/issue39948.go2"},
{"fixedbugs/issue39976.go2"},
{"fixedbugs/issue39982.go2"},
{"fixedbugs/issue40037.go2"},
}

var fset = token.NewFileSet()
Expand Down
10 changes: 10 additions & 0 deletions src/go/types/fixedbugs/issue40037.go2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

// from issue #40037
type comp(type T comparable) T
type K /* ERROR illegal cycle */ comp(K) // becomes 'type K K', where K is comparable

// from issue #39634 crash 22
type T(type _ interface{ a() }) int
type A(type P) T(A(int))

8 changes: 8 additions & 0 deletions src/go/types/subst.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ func (check *Checker) instantiate(pos token.Pos, typ Type, targs []Type, poslist
// - check only if we have methods
check.completeInterface(token.NoPos, iface)
if len(iface.allMethods) > 0 {
// Break cycle in cases like
//
// type constr(type T comparable) T
// type K constr(K)
if t1 := typ.Named(); t1 != nil && t1.underlying == t1.orig {
break
}

// If the type argument is a type parameter itself, its pointer designation
// must match the pointer designation of the callee's type parameter.
// If the type argument is a pointer to a type parameter, the type argument's
Expand Down