Skip to content

Commit

Permalink
fix: fix an ICE happening when we call a closure result from if/else
Browse files Browse the repository at this point in the history
  • Loading branch information
alehander92 committed Aug 3, 2023
1 parent de072ae commit 636b29a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ 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);

let ret = twice(add1, 3);

test_array_functions();
Expand Down
13 changes: 12 additions & 1 deletion crates/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,18 @@ impl<'interner> Monomorphizer<'interner> {
let args = vecmap(args, Self::convert_type);
let ret = Box::new(Self::convert_type(ret));
let env = Box::new(Self::convert_type(env));
ast::Type::Function(args, ret, 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),
]),
_ => {
unreachable!(
"internal Type::Function env should be either a Unit or a Tuple, not {env}"
)
}
}
}

HirType::MutableReference(element) => {
Expand Down

0 comments on commit 636b29a

Please sign in to comment.