Resolver - Improved handling of 'return'
This commit is contained in:
parent
57a5a62300
commit
ee53c2fba4
1 changed files with 5 additions and 5 deletions
|
@ -383,13 +383,13 @@ impl VarResolver for StmtNode {
|
||||||
StmtNode::Return {
|
StmtNode::Return {
|
||||||
token,
|
token,
|
||||||
value: Some(expr),
|
value: Some(expr),
|
||||||
} => {
|
} => match rs.current_type() {
|
||||||
if !matches!(rs.current_type(), ScopeType::Method | ScopeType::Function) {
|
ScopeType::TopLevel => rs.error(token, "'return' not allowed here"),
|
||||||
|
ScopeType::Initializer => {
|
||||||
rs.error(token, "'return' with value is not allowed here")
|
rs.error(token, "'return' with value is not allowed here")
|
||||||
} else {
|
|
||||||
expr.resolve(rs)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
_ => 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