1
0
Fork 0
mirror of synced 2025-09-23 04:08:33 +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 {
errors.push(ErrorInner {
pos: Some(pos),
message: "Expected a return statement".to_string(),
});
match &s.output {
box DeclarationType::Tuple(tuple_type)
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);

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() {}