-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: recursive functions cause broken InitOrder #10709
Comments
Here's a more "realistic" example in the sense that the code would actually run (rather than lead to endless recursion and thus stack overflow):
go/types also reports the wrong initialization order in this case. The issue is that initialization cycles through functions only are silently ignored and then lead to a wrong initialization order (initorder.go:52). Instead, cycles involving only functions should probably be removed beforehand. |
This bug makes it impossible to use go/types as part of a frontend for a compiler. Here's an example of a Go package that is compiled incorrectly and fails at runtime because of incorrect variable initialization order: https://github.com/vanadium/go.v23/tree/master/vdl |
This is still high on the list for 1.7. |
CL https://golang.org/cl/23442 mentions this issue. |
Also: Added some test cases for issue golang#10709. No impact when debugging output is disabled (default). For golang#10709. Change-Id: I0751befb222c86d46225377a674f6bad2990349e Reviewed-on: https://go-review.googlesource.com/23442 Reviewed-by: Alan Donovan <adonovan@google.com>
CL https://golang.org/cl/24131 mentions this issue. |
If you have a recursive function called in an
init
function (or toplevelvar
block), the parsedInitOrder
can be broken. It will report that some variables should be initialized before their dependencies.For example, in
program.go
below, we have two variables:m
andfooInst
. The variablem
depends onfooInst
, andfooInst
is the result of a recursive function call.The initialization order should be
fooInst
thenm
.However, after parsing
program.go
withparser.ParseFile
and then callingconfig.Check
, the resultingInitOrder
hasm
initialized beforefooInst
.Here is the parsing program I used:
And the output:
This order is clearly broken, since
m
cannot be initialized beforefooInst
.(All tests done with go version go1.4 linux/amd64)
The text was updated successfully, but these errors were encountered: