-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: fails with stack overflow using generics and self referential function type #51832
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
Comments
I found this similar defect that may be related though the file exhibiting the recursion is different and the example is not well distilled #39695 |
Error is
|
Looks like a bug in the 1.18 noder code. The type checker (types2) has no problems with this code. With the unified build this compiles and runs fine and prints |
I managed to distill the code further looking at the subr.go code that falls into recursion There is no need for fancy generics. Just any generics used alongside self referring function type seem to trigger this package main
type F func() F
func do[T any]() F {
return nil
}
func main() {
do[int]()
} |
Change https://go.dev/cl/394494 mentions this issue: |
ping: this is a release blocker that hasn't been updated in a while. |
Change https://go.dev/cl/406714 mentions this issue: |
What version of Go are you using (
go version
)? go version go1.18 windows/amd64Does this issue reproduce with the latest release? Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I want to define a constraint on the pointer receiver of a type and also have a self referential function type.
This combination seem to trigger infinite recursion and stack overflow
Here is link to the go playground https://go.dev/play/p/aOb7OSImUuf
Here are the stack overflow discussions about adding interface constraint on the pointer receiver of a type T
https://stackoverflow.com/questions/71547015/how-to-define-type-constraint-on-pointer-receiver-ingolang/71547820#71547820
https://stackoverflow.com/questions/69573113/how-can-i-instantiate-a-new-pointer-of-type-argument-with-generic-go
Here is a working sample that does not have the self referring function type https://go.dev/play/p/myw6FAosPjK
Here is the failing code just in case
What did you expect to see?
Successful compilation and run.
What did you see instead?
Stack overflow error on
go build ./...
The text was updated successfully, but these errors were encountered: