| author | |
| committer | |
| log | 278c32976e93f4900c634913fb2bb06f6a7ecf87 |
| tree | f4d58bc840b25ccb6281223d466a2d8a5effe9c1 |
| parent | 5321afcf9c633c5dc0da5148981dfdbd61606f1a |
Closes #127683 files changed, 24 insertions(+), 1 deletions(-)
lib/std/zig/Ast.zig+4| ... | ... | @@ -359,6 +359,9 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { |
| 359 | 359 | .expected_var_const => { |
| 360 | 360 | return stream.writeAll("expected 'var' or 'const' before variable declaration"); |
| 361 | 361 | }, |
| 362 | .wrong_equal_var_decl => { | |
| 363 | return stream.writeAll("variable initialized with '==' instead of '='"); | |
| 364 | }, | |
| 362 | 365 | |
| 363 | 366 | .expected_token => { |
| 364 | 367 | const found_tag = token_tags[parse_error.token + @boolToInt(parse_error.token_is_prev)]; |
| ... | ... | @@ -2583,6 +2586,7 @@ pub const Error = struct { |
| 2583 | 2586 | invalid_ampersand_ampersand, |
| 2584 | 2587 | c_style_container, |
| 2585 | 2588 | expected_var_const, |
| 2589 | wrong_equal_var_decl, | |
| 2586 | 2590 | |
| 2587 | 2591 | zig_style_container, |
| 2588 | 2592 | previous_field, |
lib/std/zig/parse.zig+12-1| ... | ... | @@ -812,7 +812,18 @@ const Parser = struct { |
| 812 | 812 | const align_node = try p.parseByteAlign(); |
| 813 | 813 | const addrspace_node = try p.parseAddrSpace(); |
| 814 | 814 | const section_node = try p.parseLinkSection(); |
| 815 | const init_node: Node.Index = if (p.eatToken(.equal) == null) 0 else try p.expectExpr(); | |
| 815 | const init_node: Node.Index = switch (p.token_tags[p.tok_i]) { | |
| 816 | .equal_equal => blk: { | |
| 817 | try p.warn(.wrong_equal_var_decl); | |
| 818 | p.tok_i += 1; | |
| 819 | break :blk try p.expectExpr(); | |
| 820 | }, | |
| 821 | .equal => blk: { | |
| 822 | p.tok_i += 1; | |
| 823 | break :blk try p.expectExpr(); | |
| 824 | }, | |
| 825 | else => 0, | |
| 826 | }; | |
| 816 | 827 | if (section_node == 0 and addrspace_node == 0) { |
| 817 | 828 | if (align_node == 0) { |
| 818 | 829 | return p.addNode(.{ |
lib/std/zig/parser_test.zig+8| ... | ... | @@ -5145,6 +5145,14 @@ test "zig fmt: make single-line if no trailing comma" { |
| 5145 | 5145 | ); |
| 5146 | 5146 | } |
| 5147 | 5147 | |
| 5148 | test "zig fmt: variable initialized with ==" { | |
| 5149 | try testError( | |
| 5150 | \\comptime { | |
| 5151 | \\ var z: u32 == 12 + 1; | |
| 5152 | \\} | |
| 5153 | , &.{.wrong_equal_var_decl}); | |
| 5154 | } | |
| 5155 | ||
| 5148 | 5156 | test "zig fmt: missing const/var before local variable" { |
| 5149 | 5157 | try testError( |
| 5150 | 5158 | \\comptime { |