check return statement count is one
This commit is contained in:
parent
76f1c0742d
commit
53d9a37f69
3 changed files with 30 additions and 2 deletions
4
zokrates_cli/examples/compile_errors/no_return.zok
Normal file
4
zokrates_cli/examples/compile_errors/no_return.zok
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
def foo():
|
||||||
|
|
||||||
|
def main():
|
||||||
|
return
|
||||||
3
zokrates_cli/examples/compile_errors/two_return.zok
Normal file
3
zokrates_cli/examples/compile_errors/two_return.zok
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
def main():
|
||||||
|
return
|
||||||
|
return
|
||||||
|
|
@ -651,6 +651,8 @@ impl<'ast> Checker<'ast> {
|
||||||
) -> Result<TypedFunction<'ast, T>, Vec<ErrorInner>> {
|
) -> Result<TypedFunction<'ast, T>, Vec<ErrorInner>> {
|
||||||
self.enter_scope();
|
self.enter_scope();
|
||||||
|
|
||||||
|
let pos = funct_node.pos();
|
||||||
|
|
||||||
let mut errors = vec![];
|
let mut errors = vec![];
|
||||||
let funct = funct_node.value;
|
let funct = funct_node.value;
|
||||||
let mut arguments_checked = vec![];
|
let mut arguments_checked = vec![];
|
||||||
|
|
@ -672,19 +674,30 @@ impl<'ast> Checker<'ast> {
|
||||||
|
|
||||||
match self.check_signature(funct.signature, module_id, types) {
|
match self.check_signature(funct.signature, module_id, types) {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
|
let mut found_return = false;
|
||||||
|
|
||||||
for stat in funct.statements.into_iter() {
|
for stat in funct.statements.into_iter() {
|
||||||
let pos = stat.pos();
|
let pos = Some(stat.pos());
|
||||||
|
|
||||||
match self.check_statement(stat, module_id, types) {
|
match self.check_statement(stat, module_id, types) {
|
||||||
Ok(statement) => {
|
Ok(statement) => {
|
||||||
match &statement {
|
match &statement {
|
||||||
TypedStatement::Return(e) => {
|
TypedStatement::Return(e) => {
|
||||||
|
if found_return {
|
||||||
|
errors.push(ErrorInner {
|
||||||
|
pos,
|
||||||
|
message: format!("Expected a single return statement",),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
found_return = true;
|
||||||
|
|
||||||
match e.iter().map(|e| e.get_type()).collect::<Vec<_>>()
|
match e.iter().map(|e| e.get_type()).collect::<Vec<_>>()
|
||||||
== s.outputs
|
== s.outputs
|
||||||
{
|
{
|
||||||
true => {}
|
true => {}
|
||||||
false => errors.push(ErrorInner {
|
false => errors.push(ErrorInner {
|
||||||
pos: Some(pos),
|
pos,
|
||||||
message: format!(
|
message: format!(
|
||||||
"Expected ({}) in return statement, found ({})",
|
"Expected ({}) in return statement, found ({})",
|
||||||
s.outputs
|
s.outputs
|
||||||
|
|
@ -710,6 +723,14 @@ impl<'ast> Checker<'ast> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !found_return {
|
||||||
|
errors.push(ErrorInner {
|
||||||
|
pos: Some(pos),
|
||||||
|
message: format!("Expected a return statement",),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
signature = Some(s);
|
signature = Some(s);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue