Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: create a regression test for #6420 #6421

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions compiler/noirc_frontend/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>: Foo {
fn bar(self) -> Field {
self.foo()
}
}

struct MyStruct<T> {
inner: Field,
}

trait MarkerTrait {}
impl MarkerTrait for Field {}

// `MyStruct<T>` implements `Foo` only when its generic type `T` implements `MarkerTrait`.
impl<T> Foo for MyStruct<T>
where
T: MarkerTrait,
{
fn foo() -> Field {
42
}
}

// We expect this to succeed as `MyStruct<T>` satisfies `Bar`'s trait bounds
// of implementing `Foo` when `T` implements `MarkerTrait`.
impl<T> Bar<T> for MyStruct<T>
where
T: MarkerTrait,
{
fn bar(self) -> Field {
31415
}
}

fn main() {
let foo: MyStruct<Field> = MyStruct { inner: 42 };
let _ = foo.bar();
}
"#;
assert_no_errors(src);
}
Loading