Implement return statements at root level
This commit is contained in:
parent
a3a2df552d
commit
a39d879c40
@ -60,8 +60,12 @@ impl AbstractTree for Root {
|
||||
let mut value = Value::none();
|
||||
|
||||
for statement in &self.statements {
|
||||
if let Statement::Return(inner_statement) = statement {
|
||||
return inner_statement.run(source, context);
|
||||
} else {
|
||||
value = statement.run(source, context)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(value)
|
||||
}
|
||||
|
@ -476,4 +476,18 @@ mod blocks {
|
||||
Ok(Value::Integer(1))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn root_returns_like_block() {
|
||||
assert_eq!(
|
||||
interpret(
|
||||
"
|
||||
return 1
|
||||
1 + 1
|
||||
3
|
||||
"
|
||||
),
|
||||
Ok(Value::Integer(1))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user