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: strange initialization loop error #43741
Comments
looks like it behaves according to spec, package initialization:
|
Here, how [edit] In other words, |
The spec is intended to be clear and straightforward to implement for all Go compilers. This is working as intended. |
But it looks the rule is unnecessarily too strict. |
The rule is stricter than it has to be, but not unnecessarily so. A less strict rule would have to distinguish between a reference to a function and a call of that function, and would have to work for code like var a = func() int { x := f; return x() }() Since the most important goal is a spec that is clear and straightforward to implement for all Go compilers, we did not try to write a spec that would handle cases like that in their full generality. |
What version of Go are you using (
go version
)?go1.15
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?What did you do?
Tried to compile the following code:
What did you expect to see?
It should successfully compile, since
f
isn't called duringa
initialization.What did you see instead?
Compiler returns the following error:
Additional details
The following code with identical behavior successfully compiles:
This minimal code snipped has been reduced from real production code, which uses global function table for expression evaluation. Below is a pseudo-code:
The text was updated successfully, but these errors were encountered: