Skip to content

Commit

Permalink
feat: Implement where clauses on impls (#3324)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher authored Oct 27, 2023
1 parent 4a2fce5 commit 4c3d1de
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,13 @@ impl<'a> ModCollector<'a> {
for trait_impl in impls {
let trait_name = trait_impl.trait_name.clone();

let unresolved_functions =
let mut unresolved_functions =
self.collect_trait_impl_function_overrides(context, &trait_impl, krate);

let module = ModuleId { krate, local_id: self.module_id };

for (_, func_id, noir_function) in &unresolved_functions.functions {
for (_, func_id, noir_function) in &mut unresolved_functions.functions {
noir_function.def.where_clause.append(&mut trait_impl.where_clause.clone());
context.def_interner.push_function(*func_id, &noir_function.def, module);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "impl_with_where_clause"
type = "bin"
authors = [""]
compiler_version = "0.10.5"

[dependencies]
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

fn main() {
let array: [Field; 3] = [1, 2, 3];
assert(array.eq(array));

// Ensure this still works if we have to infer the type of the integer literals
let array = [1, 2, 3];
assert(array.eq(array));
}

trait Eq {
fn eq(self, other: Self) -> bool;
}

impl<T, N> Eq for [T; N] where T: Eq {
fn eq(self, other: Self) -> bool {
let mut ret = true;
for i in 0 .. self.len() {
ret &= self[i].eq(other[i]);
}
ret
}
}

impl Eq for Field {
fn eq(self, other: Field) -> bool {
self == other
}
}

0 comments on commit 4c3d1de

Please sign in to comment.