mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-09-22 11:17:37 +03:00
add test for bug #430 early returns
This commit is contained in:
parent
b94c70588e
commit
dfcc77a860
@ -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);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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();
|
||||
|
7
compiler/tests/function/multiple_returns_fail.leo
Normal file
7
compiler/tests/function/multiple_returns_fail.leo
Normal file
@ -0,0 +1,7 @@
|
||||
function main () -> i8 {
|
||||
if true {
|
||||
return 1i8 //ignored
|
||||
}
|
||||
return 2i8 //ignored
|
||||
return 3i8 //returns
|
||||
}
|
Loading…
Reference in New Issue
Block a user