From 59c1a18b4311b27d51f3d6e65e7a00b660413a2b Mon Sep 17 00:00:00 2001 From: Tom French <15848336+TomAFrench@users.noreply.github.com> Date: Thu, 31 Oct 2024 19:05:18 +0000 Subject: [PATCH] chore: create a regression test for #6420 (#6421) --- compiler/noirc_frontend/src/tests/traits.rs | 50 +++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/compiler/noirc_frontend/src/tests/traits.rs b/compiler/noirc_frontend/src/tests/traits.rs index 2b5d6c1c8eb..42900d094b8 100644 --- a/compiler/noirc_frontend/src/tests/traits.rs +++ b/compiler/noirc_frontend/src/tests/traits.rs @@ -340,3 +340,53 @@ 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() { + // Regression test for https://github.com/noir-lang/noir/issues/6420 + 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); +}