-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Value updated without being assigned, results in bad output #10549
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
For additional reference, replacing the for loop with the following will produce valid output in the provided test, but not my larger project.
|
In addition, the following fails the same as before, but only when the Sphere object is in a tagged union and the material is grabbed using a switch statement. I was hoping the while loop would serve as a workaround, but alas no. test.zig
|
By default captures |
Awesome, thanks for that! I must've missed it when reading through the docs. |
Zig Version
0.9.0
Steps to Reproduce
On windows 11, using the chocolatey zig build of 0.9.0.
The following is the stripped down version of a larger project.
test.zig
do
zig run test.zig
Expected Behavior
I expect that since line 17 is only executed once, line 21 should print the same Material as line 16. However, this is not the case.
stdout:
Changing the return type of Sphere.hit to Material (non-pointer) fixes this problem. Same with leaving the pointers and manually unrolling.
If it turns out I'm doing something that invokes undefined behaviour, a compiler error or warning would be needed in this situation.
Actual Behavior
stdout:
This is one of those situations where math breaks.
I suspect that the pointer
possible_hit
is somehow being associated without_hit
, so the second iteration of the for is causing the initialization ofpossible_hit
to assign toout_hit
.The text was updated successfully, but these errors were encountered: