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
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];
}