| author | |
| committer | |
| log | e2adf3b61a32eae2182bcb94981a0b3706040f9a |
| tree | 913ea984891b64321b33009ab2f6fab63cc620c3 |
| parent | 8b1780d9396aa7bd919f2ec5e003f981bbce07d5 |
Closes #138883 files changed, 23 insertions(+), 0 deletions(-)
lib/std/zig/Ast.zig+4| ... | ... | @@ -362,6 +362,9 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { |
| 362 | 362 | .wrong_equal_var_decl => { |
| 363 | 363 | return stream.writeAll("variable initialized with '==' instead of '='"); |
| 364 | 364 | }, |
| 365 | .var_const_decl => { | |
| 366 | return stream.writeAll("use 'var' or 'const' to declare variable"); | |
| 367 | }, | |
| 365 | 368 | |
| 366 | 369 | .expected_token => { |
| 367 | 370 | const found_tag = token_tags[parse_error.token + @boolToInt(parse_error.token_is_prev)]; |
| ... | ... | @@ -2743,6 +2746,7 @@ pub const Error = struct { |
| 2743 | 2746 | c_style_container, |
| 2744 | 2747 | expected_var_const, |
| 2745 | 2748 | wrong_equal_var_decl, |
| 2749 | var_const_decl, | |
| 2746 | 2750 | |
| 2747 | 2751 | zig_style_container, |
| 2748 | 2752 | previous_field, |
lib/std/zig/parse.zig+7| ... | ... | @@ -471,6 +471,13 @@ const Parser = struct { |
| 471 | 471 | // There is not allowed to be a decl after a field with no comma. |
| 472 | 472 | // Report error but recover parser. |
| 473 | 473 | try p.warn(.expected_comma_after_field); |
| 474 | if (p.token_tags[p.tok_i] == .semicolon and p.token_tags[identifier] == .identifier) { | |
| 475 | try p.warnMsg(.{ | |
| 476 | .tag = .var_const_decl, | |
| 477 | .is_note = true, | |
| 478 | .token = identifier, | |
| 479 | }); | |
| 480 | } | |
| 474 | 481 | p.findNextContainerMember(); |
| 475 | 482 | continue; |
| 476 | 483 | }, |
lib/std/zig/parser_test.zig+12| ... | ... | @@ -5238,6 +5238,18 @@ test "zig fmt: missing const/var before local variable" { |
| 5238 | 5238 | }); |
| 5239 | 5239 | } |
| 5240 | 5240 | |
| 5241 | test "zig fmt: missing const/var before local variable" { | |
| 5242 | try testError( | |
| 5243 | \\std = foo, | |
| 5244 | \\std = foo; | |
| 5245 | \\*u32 = foo; | |
| 5246 | , &.{ | |
| 5247 | .expected_comma_after_field, | |
| 5248 | .var_const_decl, | |
| 5249 | .expected_comma_after_field, | |
| 5250 | }); | |
| 5251 | } | |
| 5252 | ||
| 5241 | 5253 | test "zig fmt: while continue expr" { |
| 5242 | 5254 | try testCanonical( |
| 5243 | 5255 | \\test { |