Skip to content

Commit

Permalink
Don't print format string with errors at compile time
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Dec 6, 2024
1 parent df08cdd commit 8a15214
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
12 changes: 11 additions & 1 deletion compiler/noirc_frontend/src/hir/comptime/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ pub enum InterpreterError {
err: Box<TypeCheckError>,
location: Location,
},
CannotInterpretFormatStringWithErrors {
location: Location,
},

// These cases are not errors, they are just used to prevent us from running more code
// until the loop can be resumed properly. These cases will never be displayed to users.
Expand Down Expand Up @@ -315,7 +318,8 @@ impl InterpreterError {
| InterpreterError::TypeAnnotationsNeededForMethodCall { location }
| InterpreterError::CannotResolveExpression { location, .. }
| InterpreterError::CannotSetFunctionBody { location, .. }
| InterpreterError::UnknownArrayLength { location, .. } => *location,
| InterpreterError::UnknownArrayLength { location, .. }
| InterpreterError::CannotInterpretFormatStringWithErrors { location } => *location,

InterpreterError::FailedToParseMacro { error, file, .. } => {
Location::new(error.span(), *file)
Expand Down Expand Up @@ -664,6 +668,12 @@ impl<'a> From<&'a InterpreterError> for CustomDiagnostic {
let secondary = format!("Evaluating the length failed with: `{err}`");
CustomDiagnostic::simple_error(msg, secondary, location.span)
}
InterpreterError::CannotInterpretFormatStringWithErrors { location } => {
let msg = "Cannot interpret format string with errors".to_string();
let secondary =
"Some of the variables to interpolate could not be evaluated".to_string();
CustomDiagnostic::simple_error(msg, secondary, location.span)
}
}
}
}
8 changes: 6 additions & 2 deletions compiler/noirc_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,12 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
result.push_str(&value.display(self.elaborator.interner).to_string());
}
} else {
// If we can't find a value for this fragment it means it already errored
// when trying to type-check it, and we don't want to error again or panic here.
// If we can't find a value for this fragment it means the interpolated value was not
// found or it errored. In this case we error here as well.
let location = self.elaborator.interner.expr_location(&id);
return Err(InterpreterError::CannotInterpretFormatStringWithErrors {
location,
});
}
}
}
Expand Down

0 comments on commit 8a15214

Please sign in to comment.