add test for bug #430 early returns

This commit is contained in:
collin 2020-12-03 13:38:05 -05:00
parent b94c70588e
commit dfcc77a860
5 changed files with 19 additions and 8 deletions

View File

@ -116,19 +116,15 @@ impl<F: Field + PrimeField, G: GroupType<F>> ConstrainedProgram<F, G> {
let expression_string = expression.to_string();
let value = self.enforce_expression(cs, file_scope, function_scope, None, expression)?;
// handle empty return value cases
// Handle empty return value cases.
match &value {
ConstrainedValue::Tuple(values) => {
if !values.is_empty() {
return Err(StatementError::unassigned(expression_string, span));
results.push((indicator.clone(), value));
}
}
_ => return Err(StatementError::unassigned(expression_string, span)),
}
let result = (indicator.to_owned(), value);
results.push(result);
}
};

View File

@ -64,15 +64,23 @@ fn test_newlines() {
#[test]
fn test_multiple_returns() {
let bytes = include_bytes!("multiple.leo");
let bytes = include_bytes!("multiple_returns.leo");
let program = parse_program(bytes).unwrap();
assert_satisfied(program);
}
#[test]
fn test_multiple_returns_fail() {
let bytes = include_bytes!("multiple_returns_fail.leo");
let program = parse_program(bytes).unwrap();
expect_compiler_error(program);
}
#[test]
fn test_multiple_returns_main() {
let program_bytes = include_bytes!("multiple_main.leo");
let program_bytes = include_bytes!("multiple_returns_main.leo");
let input_bytes = include_bytes!("input/registers.in");
let program = parse_program_with_input(program_bytes, input_bytes).unwrap();

View File

@ -0,0 +1,7 @@
function main () -> i8 {
if true {
return 1i8 //ignored
}
return 2i8 //ignored
return 3i8 //returns
}