Error for variable only set but never read #12047
Labels
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone
Main idea
This compiles without an error.
But GCC has this feature that Zig doesn't have:
Recently when messing around with C I found this warning really nice. Now I want it in Zig too. I think it's really useful and can prevent many logic errors.
So I propose having this feature in Zig too and making it an error if you only ever set a variable and never actually read it.
Extra
In fact, we might make it so smart that even this will trigger an error because the second write is useless and you aren't reading from
x
before the second write:This is more advanced but might lead to some other undesirable things (haven't thought this extra through too much) so this is optional.
So basically you'd be required to read a variable at least once before you can write it again.
This is something that GCC doesn't have.
See also: #335
See also: nektro/ziglint#15
See also: #2304
The text was updated successfully, but these errors were encountered: