Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: modify assert(x) span to cover entire statement #3177

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -814,9 +814,13 @@ where
ignore_then_commit(keyword(Keyword::Assert), parenthesized(argument_parser))
.labelled(ParsingRuleLabel::Statement)
.validate(|expressions, span, emit| {
let condition = expressions.get(0).unwrap_or(&Expression::error(span)).clone();
let mut message_str = None;
let mut condition =
expressions.get(0).cloned().unwrap_or_else(|| Expression::error(span));
// This is a bit of a hack but we want the span to cover the `assert` keyword as well.
// Perhaps `ConstrainStatement` should have it's own span rather than overloading the condition?
condition.span = span;

let mut message_str = None;
if let Some(message) = expressions.get(1) {
if let ExpressionKind::Literal(Literal::Str(message)) = &message.kind {
message_str = Some(message.clone());
Expand Down