zig
zig copied to clipboard
should `a.b = a.b` be a compiler error?
Is there ever a case where the following code is not a mistake by the developer writing the code?
const A = struct {
b: u32,
};
pub fn main() anyerror!void {
var a = A{.b = 0};
a.b = a.b;
}
I imagine volatile would be one such case. But are there any others?
I wonder if a.b = a.b should be a compiler error?
The only use case I am aware of is in other systems/languages to get explicitly a line to conditionally start debugging, which is typically done via selfassignment. Afaiu, this should not apply to Zig, which should have proper debug info to start at any line.
Further, I tend to think it is an anti-pattern to allow code, which is trivially optimized away but then I think Zig should provide some guidance what code fragments the user should use for conditional breakpoints.
Context: https://ziglang.org/documentation/master/#breakpoint does afaiu provide an unconditional breakpoint, which can not be disabled in the editor. (If it can be disabled, then I do not see a use case.)