Skip to content

Commit

Permalink
Add a test for when a cast fails
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jul 30, 2024
1 parent 1952548 commit e26060b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2744,3 +2744,25 @@ fn do_not_eagerly_error_on_cast_on_type_variable() {
"#;
assert_no_errors(src);
}

#[test]
fn error_on_cast_over_type_variable() {
let src = r#"
pub fn foo<T, U>(x: T, f: fn(T) -> U) -> U {
f(x)
}
fn main() {
let x = "a";
let _: Field = foo(x, |x| x as Field);
}
"#;

let errors = get_program_errors(src);
assert_eq!(errors.len(), 1);

assert!(matches!(
errors[0].0,
CompilationError::TypeError(TypeCheckError::TypeMismatch { .. })
));
}

0 comments on commit e26060b

Please sign in to comment.