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: add regression test for #6530 #7089

Merged
merged 7 commits into from
Jan 16, 2025
Merged
Changes from 5 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
47 changes: 46 additions & 1 deletion compiler/noirc_frontend/src/tests/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,51 @@ fn warns_if_trait_is_not_in_scope_for_generic_function_call_and_there_is_only_on
assert_eq!(trait_name, "private_mod::Foo");
}

// See https://github.com/noir-lang/noir/issues/6530
#[test]
fn regression_6530() {
let src = r#"
pub trait From<T> {
fn from(input: T) -> Self;
}

pub trait Into<T> {
fn into(self) -> T;
}

impl<T, U> Into<T> for U
where
T: From<U>,
{
fn into(self) -> T {
T::from(self)
}
}

struct Foo {
inner: Field,
}

impl Into<Field> for Foo {
fn into(self) -> Field {
self.inner
}
}

fn main() {
let foo = Foo { inner: 0 };

// This works:
let _: Field = Into::<Field>::into(foo);

// This was failing with 'No matching impl':
let _: Field = foo.into();
}
"#;
let errors = get_program_errors(src);
assert_eq!(errors.len(), 0);
}

// See https://github.com/noir-lang/noir/issues/7090
#[test]
#[should_panic]
Expand All @@ -1262,4 +1307,4 @@ fn calls_trait_method_using_struct_name_when_multiple_impls_exist() {
}
"#;
assert_no_errors(src);
}
}
Loading