aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vm.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/vm.rs b/src/vm.rs
index 8208551..791bebe 100644
--- a/src/vm.rs
+++ b/src/vm.rs
@@ -630,6 +630,16 @@ impl VM {
}
}
+ Op::AssignLocal(slot) => {
+ let slot = self.frame().stack_offset + slot;
+ let curr = Type::from(&self.stack[slot]);
+ let other = Type::from(self.pop());
+ if curr != other {
+ error!(self, ErrorKind::TypeMismatch(curr, other),
+ "Cannot assign to different type.");
+ }
+ }
+
Op::Return => {
let a = self.pop();
let inner = self.frame().block.borrow();
@@ -819,6 +829,9 @@ mod tests {
}",
[ErrorKind::ValueError(Op::Call(0), _)]);
+ test_string!(invalid_assign, "a := 1\na = 0.1\n",
+ [ErrorKind::TypeMismatch(Type::Int, Type::Float)]);
+
test_string!(wrong_params, "
f : fn -> int = fn a: int -> int {}",
[ErrorKind::TypeMismatch(_, _), ErrorKind::TypeMismatch(Type::Void, Type::Int)]);