From c172880ae47ec4906cda662801bd4b7866c9586b Mon Sep 17 00:00:00 2001 From: Michael J Klein Date: Thu, 16 Jan 2025 13:40:35 -0500 Subject: [PATCH] chore: add regression test for #6530 (#7089) --- compiler/noirc_frontend/src/tests/traits.rs | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/compiler/noirc_frontend/src/tests/traits.rs b/compiler/noirc_frontend/src/tests/traits.rs index 30dd994bf2e..8d3a63f65cf 100644 --- a/compiler/noirc_frontend/src/tests/traits.rs +++ b/compiler/noirc_frontend/src/tests/traits.rs @@ -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 { + fn from(input: T) -> Self; + } + + pub trait Into { + fn into(self) -> T; + } + + impl Into for U + where + T: From, + { + fn into(self) -> T { + T::from(self) + } + } + + struct Foo { + inner: Field, + } + + impl Into for Foo { + fn into(self) -> Field { + self.inner + } + } + + fn main() { + let foo = Foo { inner: 0 }; + + // This works: + let _: Field = Into::::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]