remove compiler return check

This commit is contained in:
Protryon 2021-02-02 19:33:30 -08:00
parent 2657c448a0
commit fcbb5e4fd9
5 changed files with 27 additions and 10 deletions

View File

@ -48,16 +48,6 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
// Initialize empty return value. // Initialize empty return value.
let mut return_value = ConstrainedValue::Tuple(vec![]); 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 // Find the return value
let mut ignored = vec![]; let mut ignored = vec![];
let mut found_return = false; let mut found_return = false;

View File

@ -0,0 +1,7 @@
function main(x: u8) -> u8 {
if x == 2u8 {
return 3u8
} else {
return 4u8
}
}

View File

@ -0,0 +1,5 @@
[main]
x: u8 = 1u8;
[registers]
x: u8 = 0;

View File

@ -16,6 +16,19 @@
use crate::{assert_satisfied, expect_asg_error, get_output, parse_program, parse_program_with_input}; 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] #[test]
fn test_empty() { fn test_empty() {
let program_string = include_str!("empty.leo"); let program_string = include_str!("empty.leo");

View File

@ -0,0 +1,2 @@
[registers]
x: u8 = 4;