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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@findleyr
Copy link
Contributor

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
@findleyr findleyr added release-blocker NeedsFix The path to resolution is known, but the work has not been done. labels Dec 9, 2020
@griesemer
Copy link
Contributor

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

@gopherbot
Copy link

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

@gopherbot
Copy link

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

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>
@golang golang locked and limited conversation to collaborators Dec 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Projects
None yet
Development

No branches or pull requests

3 participants