Merge pull request #448 from AleoHQ/fix/tuple-cond-select

fix error when selecting return between two tuples
This commit is contained in:
Collin Chin 2020-11-24 10:28:11 -05:00 committed by GitHub
commit 66dddd992d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -457,7 +457,7 @@ impl<F: Field + PrimeField, G: GroupType<F>> CondSelectGadget<F> for Constrained
ConstrainedValue::Array(array)
}
(ConstrainedValue::Tuple(tuple_1), ConstrainedValue::Array(tuple_2)) => {
(ConstrainedValue::Tuple(tuple_1), ConstrainedValue::Tuple(tuple_2)) => {
let mut array = Vec::with_capacity(tuple_1.len());
for (i, (first, second)) in tuple_1.iter().zip(tuple_2.iter()).enumerate() {

View File

@ -184,3 +184,11 @@ fn test_return_tuple() {
assert_satisfied(program);
}
#[test]
fn test_return_tuple_conditional() {
let bytes = include_bytes!("return_tuple_conditional.leo");
let program = parse_program(bytes).unwrap();
assert_satisfied(program);
}

View File

@ -0,0 +1,15 @@
// Returns a tuple using a conditional "if" statement.
function tuple_conditional () -> (
i64,
i64
) {
if true {
return (1, 1)
} else {
return (2, 2)
}
}
function main() {
let t = tuple_conditional();
}