1
0

Implement return statements at root level

This commit is contained in:
Jeff 2023-12-31 14:09:03 -05:00
parent a3a2df552d
commit a39d879c40
2 changed files with 19 additions and 1 deletions

View File

@ -60,7 +60,11 @@ impl AbstractTree for Root {
let mut value = Value::none(); let mut value = Value::none();
for statement in &self.statements { for statement in &self.statements {
value = statement.run(source, context)?; if let Statement::Return(inner_statement) = statement {
return inner_statement.run(source, context);
} else {
value = statement.run(source, context)?;
}
} }
Ok(value) Ok(value)

View File

@ -476,4 +476,18 @@ mod blocks {
Ok(Value::Integer(1)) Ok(Value::Integer(1))
); );
} }
#[test]
fn root_returns_like_block() {
assert_eq!(
interpret(
"
return 1
1 + 1
3
"
),
Ok(Value::Integer(1))
);
}
} }