1
0
Fork 0
mirror of synced 2025-09-23 12:18:44 +00:00

make return statement optional

This commit is contained in:
dark64 2022-08-29 15:17:15 +02:00
parent 8057d2714d
commit ea98c92879
4 changed files with 30 additions and 9 deletions

View file

@ -1,5 +0,0 @@
def foo() {}
def main() {
return;
}

View file

@ -1186,10 +1186,22 @@ impl<'ast, T: Field> Checker<'ast, T> {
} }
if !found_return { if !found_return {
errors.push(ErrorInner { match &s.output {
pos: Some(pos), box DeclarationType::Tuple(tuple_type)
message: "Expected a return statement".to_string(), if tuple_type.elements.is_empty() =>
}); {
statements_checked.push(TypedStatement::Return(TypedExpression::Tuple(
TupleExpressionInner::Value(vec![])
.annotate(TupleType::new(vec![])),
)))
}
_ => {
errors.push(ErrorInner {
pos: Some(pos),
message: "Expected a return statement".to_string(),
});
}
}
} }
signature = Some(s); signature = Some(s);

View file

@ -0,0 +1,5 @@
{
"entry_point": "./tests/tests/no_return.zok",
"tests": [
]
}

View file

@ -0,0 +1,9 @@
def foo() {
return;
}
def bar() {
return foo();
}
def main() {}