Skip to content

Commit

Permalink
refactor: moved test to a regression fn, cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
alehander92 committed Aug 3, 2023
1 parent 636b29a commit ca996ae
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
33 changes: 19 additions & 14 deletions crates/nargo_cli/tests/test_data/higher_order_functions/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,7 @@ fn main() -> pub Field {
x += 1;
assert(closure_capturing_mutable(1) == 5);

// Fixing an ICE, where rewriting the closures
// during monomorphization didn't correspond
// to an internal `if` type
// found by @jfecher:
// https://github.com/noir-lang/noir/pull/1959#issuecomment-1658992989
let x2: u32 = 32;

let closure_if_else = if x2 > 2 {
|| x2
} else {
|| x2 + 2342
};

assert(closure_if_else() == 32);
regression_2154();

let ret = twice(add1, 3);

Expand Down Expand Up @@ -100,3 +87,21 @@ fn add1(x: Field) -> Field {
fn twice(f: fn(Field) -> Field, x: Field) -> Field {
f(f(x))
}

// Fixing an ICE, where rewriting the closures
// during monomorphization didn't correspond
// to an internal `if` type
// found by @jfecher:
// https://github.com/noir-lang/noir/pull/1959#issuecomment-1658992989
// issue https://github.com/noir-lang/noir/issues/2154
fn regression_2154() {
let x: u32 = 32;

let closure_if_else = if x > 2 {
|| x
} else {
|| x + 2342
};

assert(closure_if_else() == 32);
}
12 changes: 6 additions & 6 deletions crates/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,12 +689,12 @@ impl<'interner> Monomorphizer<'interner> {
HirType::Function(args, ret, env) => {
let args = vecmap(args, Self::convert_type);
let ret = Box::new(Self::convert_type(ret));
let env = Box::new(Self::convert_type(env));
match (*env).clone() {
ast::Type::Unit => ast::Type::Function(args, ret, env),
ast::Type::Tuple(elements) => ast::Type::Tuple(vec![
elements[0].clone(),
ast::Type::Function(args, ret, env),
let env = Self::convert_type(env);
match &env {
ast::Type::Unit => ast::Type::Function(args, ret, Box::new(env)),
ast::Type::Tuple(_elements) => ast::Type::Tuple(vec![
env.clone(),
ast::Type::Function(args, ret, Box::new(env)),
]),
_ => {
unreachable!(
Expand Down

0 comments on commit ca996ae

Please sign in to comment.