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

chore: box ParserErrors in InterpreterError #7373

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/comptime/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
location: Location,
},
FailedToParseMacro {
error: ParserError,
error: Box<ParserError>,
tokens: String,
rule: &'static str,
file: FileId,
Expand Down Expand Up @@ -539,7 +539,7 @@

let push_the_problem_on_the_library_author = "To avoid this error in the future, try adding input validation to your macro. Erroring out early with an `assert` can be a good way to provide a user-friendly error message".into();

let mut diagnostic = CustomDiagnostic::from(error);
let mut diagnostic = CustomDiagnostic::from(error.as_ref());
// Swap the parser's primary note to become the secondary note so that it is
// more clear this error originates from failing to parse a macro.
let secondary = std::mem::take(&mut diagnostic.message);
Expand Down Expand Up @@ -648,7 +648,7 @@
}
InterpreterError::GenericNameShouldBeAnIdent { name, location } => {
let msg =
"Generic name needs to be a valid identifer (one word beginning with a letter)"

Check warning on line 651 in compiler/noirc_frontend/src/hir/comptime/errors.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (identifer)
.to_string();
let secondary = format!("`{name}` is not a valid identifier");
CustomDiagnostic::simple_error(msg, secondary, location.span)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ where
F: FnOnce(&mut Parser<'a>) -> T,
{
Parser::for_tokens(quoted).parse_result(parsing_function).map_err(|mut errors| {
let error = errors.swap_remove(0);
let error = Box::new(errors.swap_remove(0));
let tokens = tokens_to_string(tokens, interner);
InterpreterError::FailedToParseMacro { error, tokens, rule, file: location.file }
})
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/comptime/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@
Value::Expr(ExprValue::Statement(statement))
}

pub(crate) fn lvalue(lvaue: LValue) -> Self {

Check warning on line 102 in compiler/noirc_frontend/src/hir/comptime/value.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (lvaue)
Value::Expr(ExprValue::LValue(lvaue))

Check warning on line 103 in compiler/noirc_frontend/src/hir/comptime/value.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (lvaue)
}

pub(crate) fn pattern(pattern: Pattern) -> Self {
Expand Down Expand Up @@ -278,7 +278,7 @@
Ok(expr)
}
Err(mut errors) => {
let error = errors.swap_remove(0);
let error = Box::new(errors.swap_remove(0));
let file = location.file;
let rule = "an expression";
let tokens = tokens_to_string(tokens, elaborator.interner);
Expand Down Expand Up @@ -608,7 +608,7 @@
Ok(expr)
}
Err(mut errors) => {
let error = errors.swap_remove(0);
let error = Box::new(errors.swap_remove(0));
let file = location.file;
let tokens = tokens_to_string(tokens, elaborator.interner);
Err(InterpreterError::FailedToParseMacro { error, file, tokens, rule })
Expand Down
Loading