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 {
|
||||
token,
|
||||
value: Some(expr),
|
||||
} => {
|
||||
if !matches!(rs.current_type(), ScopeType::Method | ScopeType::Function) {
|
||||
} => match rs.current_type() {
|
||||
ScopeType::TopLevel => rs.error(token, "'return' not allowed here"),
|
||||
ScopeType::Initializer => {
|
||||
rs.error(token, "'return' with value is not allowed here")
|
||||
} else {
|
||||
expr.resolve(rs)
|
||||
}
|
||||
}
|
||||
_ => expr.resolve(rs),
|
||||
},
|
||||
|
||||
StmtNode::Expression(expr) => expr.resolve(rs),
|
||||
StmtNode::Print(expr) => expr.resolve(rs),
|
||||
|
|
Loading…
Reference in a new issue