zig
zig copied to clipboard
void union member causes inline for to generate incorrect code
Code sample is based on zig-bare: https://gist.github.com/leroycep/c0e1a85bcc558cd33a87143a26098128
The Reader
takes a tagged union and iterates over its fields to check if the next byte is equal to the tag value. If it is the Reader
will parse the field_type
of that union variant. The bug is that a union member with a field_type
of void
will make the code for parsing the void member always run after the other variant has been parsed.
Now, if you manually check for a field_type == void
and return before calling readAllowVoid
(like this commented out line does) it will prevent this from happening.
I just want to attest that this bug can cause very hard to debug issues. When serialising a union(enum) that had a void member as one of the possible structs, the resulting 'inline for' created some infinite loop.
Since the issue is in the generated code, this becomes almost impossible to figure out since nothing obvious shows up in a debugger.
Is this issue stale?
The code sample given works as expected on master.