If any line in a block has indentation, then all lines in the block must have the same indentation.
Additionally, the indentation level of a block must be greater than or equal to indentation level of the parent block.
While I agree with the outcome, wouldn't this mean the language becomes whitespace-sensitive for the first time? That is, if this is part of the spec and not just a compiler feature.
It's different from disallowing hard tabs because \t is just an illegal byte. zig fmt accepts and fixes tabs so that the parser can remain simpler, whereas it seems like this will introduce more bookkeeping into the parser.
I wonder if zig fmt or zig fmt --exit-non-zero-when-code-aint-pretty should be in charge of this?
@hryx I think it's important to make this part of the language spec. It makes this example invalid according to the language specification:
if (match_cond)
x.removeThing(y);
x.swap(z);
Which means that the above code is not valid Zig.
Is this meant to be implemented for stage1 as well?
Quoted from #4294
I'm confident in this decision.
Any reason for the public eyes?
If I have to choose both terseness and safety, I would prefer enforcing brackets on multi-line if(), which is much better for reading code although one may make the same old mistake when writing code and you may wonder wheter it was caused by code reformater or something else.
this sounds like something that zig fmt should be in charge of. while zig doesn't have warnings,
if (match_cond)
x.removeThing(y);
x.swap(z);
seems more appropriate as a warning (or a note) rather than an error, or the sort of thing that should go in a zig style guide.
Most helpful comment
@hryx I think it's important to make this part of the language spec. It makes this example invalid according to the language specification:
Which means that the above code is not valid Zig.