Skip to content

Commit

Permalink
feat: better error message for misplaced doc comments
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Sep 10, 2024
1 parent d6f60d7 commit 90e87e0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions compiler/noirc_frontend/src/parser/errors.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::ast::{Expression, IntegerBitSize};
use crate::lexer::errors::LexerErrorKind;
use crate::lexer::token::Token;
use crate::token::TokenKind;
use small_ord_set::SmallOrdSet;
use thiserror::Error;

Expand Down Expand Up @@ -211,8 +212,17 @@ impl<'a> From<&'a ParserError> for Diagnostic {
other => Diagnostic::simple_error(format!("{other}"), String::new(), error.span),
},
None => {
let primary = error.to_string();
Diagnostic::simple_error(primary, String::new(), error.span)
if matches!(
error.found.kind(),
TokenKind::InnerDocComment | TokenKind::OuterDocComment
) {
let primary = "This doc comment doesn't document anything".to_string();
let secondary = "Consider changing it to a regular `//` comment".to_string();
Diagnostic::simple_error(primary, secondary, error.span)
} else {
let primary = error.to_string();
Diagnostic::simple_error(primary, String::new(), error.span)
}
}
}
}
Expand Down

0 comments on commit 90e87e0

Please sign in to comment.