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

catch undefined variables in return statements

This commit is contained in:
schaeff 2018-01-22 18:37:16 +01:00
parent c2b6f6f4ac
commit e7ca2ab9e1

View file

@ -183,7 +183,10 @@ impl Checker {
Ok(())
}
Expression::Number(_) => Ok(()),
Expression::List(values) => {
Expression::List(exprs) => {
for expr in exprs {
self.check_expression(expr)?
}
Ok(())
}
}
@ -443,4 +446,27 @@ mod tests {
let mut checker = Checker::new_with_args(HashSet::new(), 0, HashSet::new());
assert_eq!(checker.check_function(bar), Err(("Function definition for function ??? with ??? argument(s) not found.".to_string())));
}
#[test]
fn return_undefined() {
// def bar():
// return a, b
// should fail
let bar_statements: Vec<Statement<FieldPrime>> = vec![Statement::Return(
Expression::List(vec![
Expression::Identifier("a".to_string()),
Expression::Identifier("b".to_string())
])
)];
let bar = Function {
id: "bar".to_string(),
arguments: vec![],
statements: bar_statements,
return_count: 2
};
let mut checker = Checker::new_with_args(HashSet::new(), 0, HashSet::new());
assert_eq!(checker.check_function(bar), Err(("\"a\" is undefined".to_string())));
}
}