aboutsummaryrefslogtreecommitdiff
path: root/src/interpret
diff options
context:
space:
mode:
Diffstat (limited to 'src/interpret')
-rw-r--r--src/interpret/operator.rs2
-rw-r--r--src/interpret/walker.rs10
2 files changed, 8 insertions, 4 deletions
diff --git a/src/interpret/operator.rs b/src/interpret/operator.rs
index 057f942..9a68a7f 100644
--- a/src/interpret/operator.rs
+++ b/src/interpret/operator.rs
@@ -280,7 +280,7 @@ impl<'t> ValueOperator<'t> {
Err(WalkerError {
kind: WalkerErrorKind::Return(returned_value),
..
- }) => Ok(returned_value),
+ }) => Ok(returned_value.unwrap_or_else(|| Value::void(self.types))),
Err(x) => Err(CallError::InsideFunction(x)),
}
}
diff --git a/src/interpret/walker.rs b/src/interpret/walker.rs
index 7c86780..07e127d 100644
--- a/src/interpret/walker.rs
+++ b/src/interpret/walker.rs
@@ -62,12 +62,16 @@ impl Walker {
println!("{}", result);
None
}
- // FIXME: Returns are always expected to have a return even though `return;` is valid.
StatementKind::Return(node) => {
+ let returned = match node {
+ Some(e) => Some(self.walk_expression(e)?),
+ None => None,
+ };
+
// If there's a function running above us it will catch this error.
return Err(WalkerError::new(
statement.at,
- WalkerErrorKind::Return(self.walk_expression(node)?),
+ WalkerErrorKind::Return(returned),
));
}
StatementKind::Break(node) => {
@@ -381,5 +385,5 @@ pub enum WalkerErrorKind {
LoopBreak(Option<Value>),
// Same as with the loop control errors, but for functions.
#[error("Return statements are only valid inside functions.")]
- Return(Value),
+ Return(Option<Value>),
}