Resolver - Check return statements in the resolver
This commit is contained in:
parent
406400bf71
commit
57a5a62300
1 changed files with 12 additions and 6 deletions
|
@ -376,14 +376,20 @@ impl VarResolver for StmtNode {
|
||||||
})
|
})
|
||||||
.and_then(|_| body.resolve(rs)),
|
.and_then(|_| body.resolve(rs)),
|
||||||
|
|
||||||
|
StmtNode::Return { token, value: None } => match rs.current_type() {
|
||||||
|
ScopeType::TopLevel => rs.error(token, "'return' not allowed here"),
|
||||||
|
_ => Ok(()),
|
||||||
|
},
|
||||||
StmtNode::Return {
|
StmtNode::Return {
|
||||||
token: _,
|
token,
|
||||||
value: None,
|
|
||||||
} => Ok(()),
|
|
||||||
StmtNode::Return {
|
|
||||||
token: _,
|
|
||||||
value: Some(expr),
|
value: Some(expr),
|
||||||
} => expr.resolve(rs),
|
} => {
|
||||||
|
if !matches!(rs.current_type(), ScopeType::Method | ScopeType::Function) {
|
||||||
|
rs.error(token, "'return' with value is not allowed here")
|
||||||
|
} else {
|
||||||
|
expr.resolve(rs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StmtNode::Expression(expr) => expr.resolve(rs),
|
StmtNode::Expression(expr) => expr.resolve(rs),
|
||||||
StmtNode::Print(expr) => expr.resolve(rs),
|
StmtNode::Print(expr) => expr.resolve(rs),
|
||||||
|
|
Loading…
Reference in a new issue