-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Unclear compile time variable scoping rules #6613
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
It seems that this behaviour was documented earlier, for example in #906 and #1470. #1470 appears to suggest (1), but perhaps (2) is more attractive as it would allow more complex uses of compile time variables. (3) produces the best results for some cases, but is more difficult to reason about when there are compile time loops. |
I think it's important to allow branching on compile time conditions. Your second code example should be allowed. But in your first code example, it definitely feels sketchy to allow an outer comptime variable to be mutated in a runtime conditional scope. |
@dbandstra It's slightly working against Zig here that there is no specific code to make the if-statement compile time. If the code had looked like this:
Then we could contrast that with this:
So essentially only allow the modification if it is in a compile time branch. |
there are several issues open about this. here are some off the top of my head: |
@andrewrk Which issue is appropriate to track if I want to see what happens with this particular issue? |
Uh oh!
There was an error while loading. Please reload this page.
If we have the following code:
Inspecting the LLVM output in 0.6.0, we note that
foo
is called with values 3, 6 and 16 respectively. There is a certain sense to this. The function will return 17 regardless of input. However if we change the code to this way:Suddenly the function returns 13.
This seems like something that could be extremely bug prone.
Possible alternatives:
The text was updated successfully, but these errors were encountered: