mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-24 07:48:04 +03:00
remove compiler return check
This commit is contained in:
parent
2657c448a0
commit
fcbb5e4fd9
@ -48,16 +48,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
|
||||
// Initialize empty return value.
|
||||
let mut return_value = ConstrainedValue::Tuple(vec![]);
|
||||
|
||||
// Error if the function or one of its branches does not return.
|
||||
if !expected_return.is_unit()
|
||||
&& results
|
||||
.iter()
|
||||
.find(|(indicator, _res)| get_indicator_value(indicator))
|
||||
.is_none()
|
||||
{
|
||||
return Err(StatementError::no_returns(&expected_return, span.to_owned()));
|
||||
}
|
||||
|
||||
// Find the return value
|
||||
let mut ignored = vec![];
|
||||
let mut found_return = false;
|
||||
|
7
compiler/tests/function/conditional_return.leo
Normal file
7
compiler/tests/function/conditional_return.leo
Normal file
@ -0,0 +1,7 @@
|
||||
function main(x: u8) -> u8 {
|
||||
if x == 2u8 {
|
||||
return 3u8
|
||||
} else {
|
||||
return 4u8
|
||||
}
|
||||
}
|
5
compiler/tests/function/input/conditional_return.in
Normal file
5
compiler/tests/function/input/conditional_return.in
Normal file
@ -0,0 +1,5 @@
|
||||
[main]
|
||||
x: u8 = 1u8;
|
||||
|
||||
[registers]
|
||||
x: u8 = 0;
|
@ -16,6 +16,19 @@
|
||||
|
||||
use crate::{assert_satisfied, expect_asg_error, get_output, parse_program, parse_program_with_input};
|
||||
|
||||
#[test]
|
||||
fn test_conditional_return() {
|
||||
let input_string = include_str!("input/conditional_return.in");
|
||||
let program_string = include_str!("conditional_return.leo");
|
||||
let program = parse_program_with_input(program_string, input_string).unwrap();
|
||||
|
||||
let expected_string = include_str!("output/conditional_return.out");
|
||||
let actual_bytes = get_output(program);
|
||||
let actual_string = std::str::from_utf8(actual_bytes.bytes().as_slice()).unwrap();
|
||||
|
||||
assert_eq!(expected_string, actual_string);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_empty() {
|
||||
let program_string = include_str!("empty.leo");
|
||||
|
2
compiler/tests/function/output/conditional_return.out
Normal file
2
compiler/tests/function/output/conditional_return.out
Normal file
@ -0,0 +1,2 @@
|
||||
[registers]
|
||||
x: u8 = 4;
|
Loading…
Reference in New Issue
Block a user