From 7a335187846d02e264307ef3f4eb58b02439ec42 Mon Sep 17 00:00:00 2001 From: Ary Borenszweig Date: Fri, 20 Dec 2024 18:08:33 -0300 Subject: [PATCH] Make sure it also works the same for primitive method calls --- compiler/noirc_frontend/src/tests/traits.rs | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/compiler/noirc_frontend/src/tests/traits.rs b/compiler/noirc_frontend/src/tests/traits.rs index dec429a2fdd..78acfcf35bd 100644 --- a/compiler/noirc_frontend/src/tests/traits.rs +++ b/compiler/noirc_frontend/src/tests/traits.rs @@ -1101,3 +1101,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"); +}