zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 2f54129087859fbd9a437d0cee33f16df523dd0b (tree)
parent 825fc654b6d0d232d7a46610b339d9c58871185e
Author: Veikka Tuominen <git@vexu.eu>
Date:   Mon, 25 Jul 2022 18:11:59 +0300

parser: add error for doc comment attached to comptime or test blocks

Diffstat:
Mlib/std/zig/Ast.zig | 8++++++++
Mlib/std/zig/parse.zig | 6++++++
Mlib/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 @@ -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 @@ -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 @@ -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" {} \\