Skip to content

Commit

Permalink
Check error output
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jul 5, 2024
1 parent c6c7574 commit 2a68af8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/ssa_gen/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl<'a> FunctionContext<'a> {
if let Some(range) = numeric_type.value_is_outside_limits(value, negative) {
let call_stack = self.builder.get_call_stack();
return Err(RuntimeError::IntegerOutOfBounds {
value,
value: if negative { -value } else { value },
typ: numeric_type,
range,
call_stack,
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/type_check/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl<'interner> TypeChecker<'interner> {
let max = 1 << bit_count;
if v >= max {
self.errors.push(TypeCheckError::OverflowingAssignment {
expr: value,
expr: -value,
ty: annotated_type.clone(),
range: format!("0..={}", max - 1),
span,
Expand Down
36 changes: 20 additions & 16 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1917,10 +1917,11 @@ fn overflowing_u8() {
let errors = get_program_errors(src);
assert_eq!(errors.len(), 1);

if let CompilationError::TypeError(TypeCheckError::OverflowingAssignment { range, .. }) =
&errors[0].0
{
assert_eq!(range, "0..=255");
if let CompilationError::TypeError(error) = &errors[0].0 {
assert_eq!(
error.to_string(),
"The literal `2⁸` cannot fit into `u8` which has range `0..=255`"
);
} else {
panic!("Expected OverflowingAssignment error, got {:?}", errors[0].0);
}
Expand All @@ -1935,10 +1936,11 @@ fn underflowing_u8() {
let errors = get_program_errors(src);
assert_eq!(errors.len(), 1);

if let CompilationError::TypeError(TypeCheckError::OverflowingAssignment { range, .. }) =
&errors[0].0
{
assert_eq!(range, "0..=255");
if let CompilationError::TypeError(error) = &errors[0].0 {
assert_eq!(
error.to_string(),
"The literal `-1` cannot fit into `u8` which has range `0..=255`"
);
} else {
panic!("Expected OverflowingAssignment error, got {:?}", errors[0].0);
}
Expand All @@ -1953,10 +1955,11 @@ fn overflowing_i8() {
let errors = get_program_errors(src);
assert_eq!(errors.len(), 1);

if let CompilationError::TypeError(TypeCheckError::OverflowingAssignment { range, .. }) =
&errors[0].0
{
assert_eq!(range, "-128..=127");
if let CompilationError::TypeError(error) = &errors[0].0 {
assert_eq!(
error.to_string(),
"The literal `2⁷` cannot fit into `i8` which has range `-128..=127`"
);
} else {
panic!("Expected OverflowingAssignment error, got {:?}", errors[0].0);
}
Expand All @@ -1971,10 +1974,11 @@ fn underflowing_i8() {
let errors = get_program_errors(src);
assert_eq!(errors.len(), 1);

if let CompilationError::TypeError(TypeCheckError::OverflowingAssignment { range, .. }) =
&errors[0].0
{
assert_eq!(range, "-128..=127");
if let CompilationError::TypeError(error) = &errors[0].0 {
assert_eq!(
error.to_string(),
"The literal `-129` cannot fit into `i8` which has range `-128..=127`"
);
} else {
panic!("Expected OverflowingAssignment error, got {:?}", errors[0].0);
}
Expand Down

0 comments on commit 2a68af8

Please sign in to comment.