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
cmd/go2go: recursive constraints doesn't work correctly #39680
Comments
Another example What did you do?https://go2goplay.golang.org/p/kd9puCHjnbE What did you expect to see?compilation fail What did you see instead?runtime: goroutine stack exceeds 1000000000-byte limit runtime: sp=0xc0203c0390 stack=[0xc0203c0000, 0xc0403c0000] fatal error: stack overflow runtime stack: runtime.throw(0x69220d, 0xe) /usr/local/go-faketime/src/runtime/panic.go:1116 +0x72 runtime.newstack() /usr/local/go-faketime/src/runtime/stack.go:1059 +0x78d runtime.morestack() /usr/local/go-faketime/src/runtime/asm_amd64.s:449 +0x8f ... |
In the latter example there is the constraint type constr(type T) interface {
type T
} I think that such a constraint is meaningless since, if I understand correctly, it simply reduces to the type T itstelf. E.g. such a |
First example is example of practical use. It's |
Change Lines 829 to 837 in 5e75416
to func optype(typ Type) Type {
if t := typ.TypeParam(); t != nil {
u := t.Bound().allTypes
if u != nil && typ != u { // prevent infinite recursion
return u
}
return theTop
}
return typ
} resolves the problem |
Your first example is simply incorrect code: Given an interface type I interface { E; type ... } the resulting type list of This code works: https://go2goplay.golang.org/p/5ddBkbO2ZJb |
As currently implemented, if |
Change https://golang.org/cl/238863 mentions this issue: |
…nal types The operational type for a type parameter T constrained by interface { type T } is the top type, not itself. The latter can lead to infinite recursions. Fix suggested by @tdakkota. Fixes #39680. Change-Id: I8a6a6c503f09294b9276965f1d9e05c5d22ec912 Reviewed-on: https://go-review.googlesource.com/c/go/+/238863 Reviewed-by: Robert Griesemer <gri@golang.org>
@tdakkota Thanks for your 2nd example and the suggested fix. It is exactly right. This is now fixed in dev.go2go. |
What version of Go are you using (
go version
)?n/a
Does this issue reproduce with the latest release?
n/a
What operating system and processor architecture are you using (
go env
)?n/a
What did you do?
https://go2goplay.golang.org/p/jWH4GUTN-pX
What did you expect to see?
or just
What did you see instead?
The text was updated successfully, but these errors were encountered: