Skip to content
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

go/types: avoid infinite recursion in Comparable #43088

Closed
findleyr opened this issue Dec 9, 2020 · 3 comments
Closed

go/types: avoid infinite recursion in Comparable #43088

findleyr opened this issue Dec 9, 2020 · 3 comments
Assignees
Milestone

Comments

@findleyr
Copy link
Contributor

@findleyr findleyr commented Dec 9, 2020

https://golang.org/cl/276374 fixes an infinite recursion in the Comparable function of the cmd/compile/internal/types2 package in the dev.typeparams branch, which is based on go/types.

This bug is present in go/types as well, though it can't be hit via normal type-checking. However, it is possible to reach via the API, for example

name := types.NewTypeName(token.NoPos, nil, "T", nil)
T := types.NewNamed(name, nil, nil)
S := types.NewStruct([]*types.Var{types.NewField(token.NoPos, nil, "x", T, false)}, nil)
T.SetUnderlying(S)
_ = types.Comparable(T)

We should probably port CL 276374 to go/types for 1.16.

CC @griesemer

@findleyr findleyr self-assigned this Dec 9, 2020
@findleyr findleyr added this to the Go1.16 milestone Dec 9, 2020
@griesemer
Copy link
Contributor

@griesemer griesemer commented Dec 9, 2020

Agreed. The fix is straight-forward and safe to include into 1.16 at this time.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 9, 2020

Change https://golang.org/cl/276374 mentions this issue: [dev.typeparams] cmd/compile/internal/types2: avoid endless recursion in Comparable predicate

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Dec 9, 2020

Change https://golang.org/cl/276552 mentions this issue: go/types: avoid endless recursion in the Comparable predicate

Loading

gopherbot pushed a commit that referenced this issue Dec 9, 2020
… in Comparable predicate

Use a map to detect recursive types.
With this we can now typecheck fixedbugs/issue8501.go.

Updates #43088.

Change-Id: I7fad6ccf6c94268473ff72b09a3158e13a7f4cc3
Reviewed-on: https://go-review.googlesource.com/c/go/+/276374
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
@gopherbot gopherbot closed this in 89f465c Dec 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants