diff --git a/compiler/noirc_frontend/src/tests/traits.rs b/compiler/noirc_frontend/src/tests/traits.rs index dd6430a94cc..2b5d6c1c8eb 100644 --- a/compiler/noirc_frontend/src/tests/traits.rs +++ b/compiler/noirc_frontend/src/tests/traits.rs @@ -262,6 +262,64 @@ fn errors_if_impl_trait_constraint_is_not_satisfied() { assert_eq!(impl_trait, "Foo"); } +#[test] +// Regression test for https://github.com/noir-lang/noir/issues/6314 +// Baz inherits from a single trait: Foo +fn regression_6314_single_inheritance() { + let src = r#" + trait Foo { + fn foo(self) -> Self; + } + + trait Baz: Foo {} + + impl Baz for T where T: Foo {} + + fn main() { } + "#; + assert_no_errors(src); +} + +#[test] +// Regression test for https://github.com/noir-lang/noir/issues/6314 +// Baz inherits from two traits: Foo and Bar +fn regression_6314_double_inheritance() { + let src = r#" + trait Foo { + fn foo(self) -> Self; + } + + trait Bar { + fn bar(self) -> Self; + } + + trait Baz: Foo + Bar {} + + impl Baz for T where T: Foo + Bar {} + + fn baz(x: T) -> T where T: Baz { + x.foo().bar() + } + + impl Foo for Field { + fn foo(self) -> Self { + self + 1 + } + } + + impl Bar for Field { + fn bar(self) -> Self { + self + 2 + } + } + + fn main() { + assert(0.foo().bar() == baz(0)); + }"#; + + assert_no_errors(src); +} + #[test] fn removes_assumed_parent_traits_after_function_ends() { let src = r#"