From a7202d313f1fe37d1c40ee3babb13daf0ab2eb5d Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 31 Oct 2024 18:11:07 +0000 Subject: [PATCH 1/2] chore: create a regression test for #6420 --- compiler/noirc_frontend/src/tests/traits.rs | 49 +++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/compiler/noirc_frontend/src/tests/traits.rs b/compiler/noirc_frontend/src/tests/traits.rs index 2b5d6c1c8eb..66f9fb5edf1 100644 --- a/compiler/noirc_frontend/src/tests/traits.rs +++ b/compiler/noirc_frontend/src/tests/traits.rs @@ -340,3 +340,52 @@ fn removes_assumed_parent_traits_after_function_ends() { "#; assert_no_errors(src); } + +#[test] +fn trait_bounds_which_are_dependent_on_generic_types_are_resolved_correctly() { + let src = r#" + trait Foo { + fn foo() -> Field; + } + + trait Bar: Foo { + fn bar(self) -> Field { + self.foo() + } + } + + struct MyStruct { + inner: Field, + } + + trait MarkerTrait {} + impl MarkerTrait for Field {} + + // `MyStruct` implements `Foo` only when its generic type `T` implements `MarkerTrait`. + impl Foo for MyStruct + where + T: MarkerTrait, + { + fn foo() -> Field { + 42 + } + } + + // We expect this to succeed as `MyStruct` satisfies `Bar`'s trait bounds + // of implementing `Foo` when `T` implements `MarkerTrait`. + impl Bar for MyStruct + where + T: MarkerTrait, + { + fn bar(self) -> Field { + 31415 + } + } + + fn main() { + let foo: MyStruct = MyStruct { inner: 42 }; + let _ = foo.bar(); + } + "#; + assert_no_errors(src); +} From 7036442be9eeb157a93594a59ba2c702ad055eda Mon Sep 17 00:00:00 2001 From: Tom French Date: Thu, 31 Oct 2024 18:12:03 +0000 Subject: [PATCH 2/2] . --- compiler/noirc_frontend/src/tests/traits.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/noirc_frontend/src/tests/traits.rs b/compiler/noirc_frontend/src/tests/traits.rs index 66f9fb5edf1..42900d094b8 100644 --- a/compiler/noirc_frontend/src/tests/traits.rs +++ b/compiler/noirc_frontend/src/tests/traits.rs @@ -343,6 +343,7 @@ fn removes_assumed_parent_traits_after_function_ends() { #[test] fn trait_bounds_which_are_dependent_on_generic_types_are_resolved_correctly() { + // Regression test for https://github.com/noir-lang/noir/issues/6420 let src = r#" trait Foo { fn foo() -> Field;