diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-07-25 18:11:59 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-07-26 12:14:59 +0300 |
| commit | 2f54129087859fbd9a437d0cee33f16df523dd0b (patch) | |
| tree | 74bd3628de297ced8104e7240c20d4abbdfe0bd3 /lib/std | |
| parent | 825fc654b6d0d232d7a46610b339d9c58871185e (diff) | |
| download | zig-2f54129087859fbd9a437d0cee33f16df523dd0b.tar.gz zig-2f54129087859fbd9a437d0cee33f16df523dd0b.zip | |
parser: add error for doc comment attached to comptime or test blocks
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/Ast.zig | 8 | ||||
| -rw-r--r-- | lib/std/zig/parse.zig | 6 | ||||
| -rw-r--r-- | lib/std/zig/parser_test.zig | 12 |
3 files changed, 14 insertions, 12 deletions
diff --git a/lib/std/zig/Ast.zig b/lib/std/zig/Ast.zig index 5eb4b11c27..9bffcb3df2 100644 --- a/lib/std/zig/Ast.zig +++ b/lib/std/zig/Ast.zig @@ -297,6 +297,12 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void { .unattached_doc_comment => { return stream.writeAll("unattached documentation comment"); }, + .test_doc_comment => { + return stream.writeAll("documentation comments cannot be attached to tests"); + }, + .comptime_doc_comment => { + return stream.writeAll("documentation comments cannot be attached to comptime blocks"); + }, .varargs_nonfinal => { return stream.writeAll("function prototype has parameter after varargs"); }, @@ -2539,6 +2545,8 @@ pub const Error = struct { invalid_bit_range, same_line_doc_comment, unattached_doc_comment, + test_doc_comment, + comptime_doc_comment, varargs_nonfinal, expected_continue_expr, expected_semi_after_decl, diff --git a/lib/std/zig/parse.zig b/lib/std/zig/parse.zig index 96b680a389..f3c219cfc6 100644 --- a/lib/std/zig/parse.zig +++ b/lib/std/zig/parse.zig @@ -259,6 +259,9 @@ const Parser = struct { switch (p.token_tags[p.tok_i]) { .keyword_test => { + if (doc_comment) |some| { + try p.warnMsg(.{ .tag = .test_doc_comment, .token = some }); + } const test_decl_node = try p.expectTestDeclRecoverable(); if (test_decl_node != 0) { if (field_state == .seen) { @@ -317,6 +320,9 @@ const Parser = struct { } }, .l_brace => { + if (doc_comment) |some| { + try p.warnMsg(.{ .tag = .test_doc_comment, .token = some }); + } const comptime_token = p.nextToken(); const block = p.parseBlock() catch |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, diff --git a/lib/std/zig/parser_test.zig b/lib/std/zig/parser_test.zig index ee1d956d08..38c2960f31 100644 --- a/lib/std/zig/parser_test.zig +++ b/lib/std/zig/parser_test.zig @@ -184,15 +184,6 @@ test "zig fmt: file ends in comment after var decl" { ); } -test "zig fmt: doc comments on test" { - try testCanonical( - \\/// hello - \\/// world - \\test "" {} - \\ - ); -} - test "zig fmt: if statment" { try testCanonical( \\test "" { @@ -2700,9 +2691,6 @@ test "zig fmt: comments in statements" { test "zig fmt: comments before test decl" { try testCanonical( - \\/// top level doc comment - \\test "hi" {} - \\ \\// top level normal comment \\test "hi" {} \\ |
