Skip to content

Commit

Permalink
fix: Allow two TypeVariable::Constant(N) to unify even if their con…
Browse files Browse the repository at this point in the history
…stants are not equal (#3225)
  • Loading branch information
jfecher authored Oct 19, 2023
1 parent 26746c5 commit cc4ca4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -684,9 +684,16 @@ impl Type {
*binding.borrow_mut() = TypeBinding::Bound(clone);
Ok(())
}
TypeVariableKind::Constant(_) | TypeVariableKind::IntegerOrField => {
Err(UnificationError)
// The lengths don't match, but neither are set in stone so we can
// just set them both to NotConstant. See issue 2370
TypeVariableKind::Constant(_) => {
// *length != target_length
drop(borrow);
*var.borrow_mut() = TypeBinding::Bound(Type::NotConstant);
*binding.borrow_mut() = TypeBinding::Bound(Type::NotConstant);
Ok(())
}
TypeVariableKind::IntegerOrField => Err(UnificationError),
},
}
}
Expand Down
8 changes: 8 additions & 0 deletions tooling/nargo_cli/tests/execution_success/slices/src/main.nr
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ fn main(x : Field, y : pub Field) {
regression_2083();
// The parameters to this function must come from witness values (inputs to main)
regression_merge_slices(x, y);
regression_2370();
}

// Ensure that slices of struct/tuple values work.
Expand Down Expand Up @@ -301,3 +302,10 @@ fn merge_slices_remove_between_ifs(x: Field, y: Field) -> [Field] {

slice
}

// Previously, we'd get a type error when trying to assign an array of a different size to
// an existing array variable. Now, we infer the variable must be a slice.
fn regression_2370() {
let mut slice = [];
slice = [1, 2, 3];
}

0 comments on commit cc4ca4b

Please sign in to comment.