Skip to content

Commit

Permalink
Make sure it also works the same for primitive method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Dec 20, 2024
1 parent c63002a commit dc6e95f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions compiler/noirc_frontend/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1007,3 +1007,36 @@ fn warns_if_trait_is_not_in_scope_for_primitive_function_call_and_there_is_only_
assert_eq!(ident.to_string(), "foo");
assert_eq!(trait_name, "private_mod::Foo");
}

#[test]
fn warns_if_trait_is_not_in_scope_for_primitive_method_call_and_there_is_only_one_trait_method() {
let src = r#"
fn main() {
let x: Field = 1;
let _ = x.foo();
}
mod private_mod {
pub trait Foo {
fn foo(self) -> i32;
}
impl Foo for Field {
fn foo(self) -> i32 {
self as i32
}
}
}
"#;
let errors = get_program_errors(src);
assert_eq!(errors.len(), 1);

let CompilationError::ResolverError(ResolverError::PathResolutionError(
PathResolutionError::TraitMethodNotInScope { ident, trait_name },
)) = &errors[0].0
else {
panic!("Expected a 'trait method not in scope' error");
};
assert_eq!(ident.to_string(), "foo");
assert_eq!(trait_name, "private_mod::Foo");
}

0 comments on commit dc6e95f

Please sign in to comment.