-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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/compile: interface definition cannot contain itself inside an anonymous interface method argument #16369
Comments
Error on tip (
|
Not a regression from 1.6, so I'm marking as 1.8. |
Are you sure it's not a regression? It seems to compile for me with 1.6. |
Hmm. It fails at run time on 1.6, but compile time at tip. Not sure whether that counts as a regression or not. |
Oh, I see. I agree: not a regression. The test case seems to work with gccgo. |
The new importer/exporter can handle this data structure w/o problem but we had to turn off the mechanism a while back because the compiler's internal type representation cannot handle such a recursive type (see trackAllTypes flag in bexport.go of the compiler). Unfortunately this broke cycle detection and we get a stack overflow. This should probably report an error, or perhaps silently pass as was the case with 1.6. Note also while this "seems to work" with 1.6, the compiler actually cannot import the resulting package anymore (syntax error in import). Any package with such an interface-recursive exported type cannot be imported - it's only useful at the top-level (main package), but in that case such a type doesn't need to be exported. With 1.6, for:
the export data looks like:
(Note the recursion that's "terminated" with Probably not a release blocker, but I'll see if there's a low-risk fix that could prevent the crash. |
PS: The reason the compiler cannot handle this type is that it "flattens" interface types: |
CL https://golang.org/cl/24979 mentions this issue. |
For #16369. Change-Id: I4c9f5a66b95558adcc1bcface164b9b2b4382d2f Reviewed-on: https://go-review.googlesource.com/24979 Reviewed-by: Alan Donovan <[email protected]>
Currently:
That's at least very clear. |
CL https://golang.org/cl/38392 mentions this issue. |
CL https://golang.org/cl/38391 mentions this issue. |
Previously, we handled recursive interfaces by deferring typechecking of interface methods, while eagerly expanding interface embeddings. This CL switches to eagerly evaluating interface methods, and deferring expanding interface embeddings to dowidth. This allows us to detect recursive interface embeddings with the same mechanism used for detecting recursive struct embeddings. Updates #16369. Change-Id: If4c0320058047f8a2d9b52b9a79de47eb9887f95 Reviewed-on: https://go-review.googlesource.com/38391 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
Backports golang.org/cl/38392 from go/internal/gcimporter. Updates golang/go#16369. Change-Id: Ic805f96e6565590987a5dae9f0f76c206fceab05 Reviewed-on: https://go-review.googlesource.com/38429 Run-TryBot: Matthew Dempsky <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
CL https://golang.org/cl/38490 mentions this issue. |
exporter.nesting was added in c7b9bd7 to mitigate #16369 which was closed in ee272bb. Remove the exporter.nesting field as it is now unused. Change-Id: I07873d1a07d6a08b11994b817a1483ffc2f5e45f Reviewed-on: https://go-review.googlesource.com/38490 Run-TryBot: Dave Cheney <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
Please answer these questions before submitting your issue. Thanks!
go version
)?go1.6.2
go env
)?I tried to define an interface that expects itself as the argument of one of its methods:
https://play.golang.org/p/oB091DHIS2
I would expect it to simply look for the desired signature of the argument passed in and accept it as valid
It seems it recursively walk the full interface definition so it enters som kind of loop
The text was updated successfully, but these errors were encountered: