Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/elaborator/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ pub(crate) fn check_trait_impl_method_matches_declaration(
// Substitute each generic on the trait function with the corresponding generic on the impl function
for (
ResolvedGeneric { type_var: trait_fn_generic, .. },
ResolvedGeneric { name, type_var: impl_fn_generic, .. },
ResolvedGeneric { name, type_var: impl_fn_generic, kind, .. },
) in trait_fn_meta.direct_generics.iter().zip(&meta.direct_generics)
{
let arg = Type::NamedGeneric(impl_fn_generic.clone(), name.clone(), Kind::Normal);
let arg = Type::NamedGeneric(impl_fn_generic.clone(), name.clone(), kind.clone());
bindings.insert(trait_fn_generic.id(), (trait_fn_generic.clone(), arg));
Comment thread
TomAFrench marked this conversation as resolved.
}

Expand Down
25 changes: 25 additions & 0 deletions compiler/noirc_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3700,3 +3700,28 @@ fn use_non_u32_generic_in_struct() {
let errors = get_program_errors(src);
assert_eq!(errors.len(), 0);
}

#[test]
fn use_numeric_generic_in_trait_method() {
let src = r#"
trait Foo {
fn foo<let N: u32>(self, x: [u8; N]) -> Self;
}

struct Bar;

impl Foo for Bar {
fn foo<let N: u32>(self, _x: [u8; N]) -> Self {
self
}
}

fn main() {
let _ = Bar{}.foo([1,2,3]);
}
"#;

let errors = get_program_errors(src);
println!("{errors:?}");
assert_eq!(errors.len(), 0);
}