mirror of
https://github.com/AleoHQ/leo.git
synced 2024-12-21 00:21:47 +03:00
fixes eq for arrays with unspecified size
This commit is contained in:
parent
012770c2c0
commit
a1aa5326ad
@ -57,6 +57,11 @@ pub fn evaluate_eq<'a, F: PrimeField, G: GroupType<F>, CS: ConstraintSystem<F>>(
|
||||
}
|
||||
(ConstrainedValue::Array(arr_1), ConstrainedValue::Array(arr_2)) => {
|
||||
let mut current = ConstrainedValue::Boolean(Boolean::constant(true));
|
||||
|
||||
if arr_1.len() != arr_2.len() {
|
||||
return Err(CompilerError::array_sizes_must_match_in_eq(arr_1.len(), arr_2.len(), span).into());
|
||||
}
|
||||
|
||||
for (i, (left, right)) in arr_1.into_iter().zip(arr_2.into_iter()).enumerate() {
|
||||
let next = evaluate_eq(&mut cs.ns(|| format!("array[{}]", i)), left, right, span)?;
|
||||
|
||||
|
@ -163,7 +163,7 @@ create_errors!(
|
||||
help: None,
|
||||
}
|
||||
|
||||
/// For when the operation has no implmentation on the type of variable received.
|
||||
/// For when the operation has no implementation on the type of variable received.
|
||||
@formatted
|
||||
incompatible_types {
|
||||
args: (operation: impl Display),
|
||||
@ -841,4 +841,11 @@ create_errors!(
|
||||
msg: "len() can only be called on an array value".to_string(),
|
||||
help: None,
|
||||
}
|
||||
|
||||
@formatted
|
||||
array_sizes_must_match_in_eq {
|
||||
args: (lhs: impl Display, rhs: impl Display),
|
||||
msg: format!("array sizes must match for comparison; left: {}, right: {}", lhs, rhs),
|
||||
help: None,
|
||||
}
|
||||
);
|
||||
|
9
tests/compiler/array_without_size/compare_fail.leo
Normal file
9
tests/compiler/array_without_size/compare_fail.leo
Normal file
@ -0,0 +1,9 @@
|
||||
/*
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
*/
|
||||
|
||||
function main() {
|
||||
let x: [u8; _] = [1u8,2];
|
||||
let z: bool = x == [1u8,2,3]; // array size mismatch
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
---
|
||||
namespace: Compile
|
||||
expectation: Fail
|
||||
outputs:
|
||||
- "Error [ECMP0376093]: array sizes must match for comparison; left: 2, right: 3\n --> compiler-test:5:19\n |\n 5 | let z: bool = x == [1u8,2,3]; // array size mismatch\n | ^^^^^^^^^^^^^^"
|
Loading…
Reference in New Issue
Block a user