You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So, I was trying to use an optional field to keep track of whether a filed in a structure should be 'usable' by using a 'null' value to flag its 'un-usability', and I ran across this odd behavior. This behavior occurs when an Optional field in a structure is set to undefined, where depending on what optimization level that is used, it ends up with a different result when checking if the value is 'null' before and after being passed through an anyopaque pointer cast and back.
I was hoping it would set the value to not-null with an undefined value, but I'm not sure exactly what the correct behavior would be after a bit more thought.
This might be related to these 2 issues, but I'm not sure what the correct behavior is based on these either:
alexrp
added
question
No questions on the issue tracker, please.
and removed
bug
Observed behavior contradicts documented or intended behavior
labels
Mar 11, 2025
Sorry for the clutter. I confused myself with this one and have now realized I probably meant to do TypeHolder{.value = @as(u32, undefined)} instead. For some reason, I thought setting the filed to undefined would set it as a not null undefeind value instead of 'nullness' and value both being undefined.
Zig Version
0.14.0
Steps to Reproduce and Observed Behavior
So, I was trying to use an optional field to keep track of whether a filed in a structure should be 'usable' by using a 'null' value to flag its 'un-usability', and I ran across this odd behavior. This behavior occurs when an Optional field in a structure is set to undefined, where depending on what optimization level that is used, it ends up with a different result when checking if the value is 'null' before and after being passed through an anyopaque pointer cast and back.
Debug
info: Before: main.TypeHolder@d148dffcb0 true
info: After: main.TypeHolder@d148dffcb0 true
ReleaseSafe
info: Before: main.TypeHolder@c1261ffbf8 false
info: After: main.TypeHolder@c1261ffbf8 true
ReleaseSmall
info: Before: main.TypeHolder@7c80fffea8 true
info: After: main.TypeHolder@7c80fffea8 true
ReleaseFast
info: Before: main.TypeHolder@dcea3ff900 false
info: After: main.TypeHolder@dcea3ff900 true
Expected Behavior
I was hoping it would set the value to not-null with an undefined value, but I'm not sure exactly what the correct behavior would be after a bit more thought.
This might be related to these 2 issues, but I'm not sure what the correct behavior is based on these either:
The text was updated successfully, but these errors were encountered: