Skip to content

Commit

Permalink
fix: error on trailing doc comment (#7300)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored Feb 5, 2025
1 parent d327462 commit a252123
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion compiler/noirc_frontend/src/parser/parser/item.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use iter_extended::vecmap;

use crate::{
parser::{labels::ParsingRuleLabel, Item, ItemKind},
parser::{labels::ParsingRuleLabel, Item, ItemKind, ParserErrorReason},
token::{Keyword, Token},
};

Expand Down Expand Up @@ -94,6 +94,10 @@ impl<'a> Parser<'a> {
let kinds = self.parse_item_kind();
let span = self.span_since(start_span);

if kinds.is_empty() && !doc_comments.is_empty() {
self.push_error(ParserErrorReason::DocCommentDoesNotDocumentAnything, start_span);
}

vecmap(kinds, |kind| Item { kind, span, doc_comments: doc_comments.clone() })
}

Expand Down Expand Up @@ -260,4 +264,18 @@ mod tests {
let error = get_single_error(&errors, span);
assert_eq!(error.to_string(), "Expected a '}' but found end of input");
}

#[test]
fn errors_on_trailing_doc_comment() {
let src = "
fn foo() {}
/// doc comment
^^^^^^^^^^^^^^^
";
let (src, span) = get_source_with_error_span(src);
let (module, errors) = parse_program(&src);
assert_eq!(module.items.len(), 1);
let error = get_single_error(&errors, span);
assert!(error.to_string().contains("Documentation comment does not document anything"));
}
}

0 comments on commit a252123

Please sign in to comment.