diff options
| author | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-17 22:53:51 +0100 |
|---|---|---|
| committer | Edvard Thörnros <edvard.thornros@gmail.com> | 2021-02-19 18:02:45 +0100 |
| commit | 79f8e81b7b4d89231fcff207ff2c13e4c24cde56 (patch) | |
| tree | 1507d2e5155814a081aedfe473015f1c6695cfb4 | |
| parent | ab05add4c3fbe25c688e16af9d8a9849669b797e (diff) | |
| download | sylt-79f8e81b7b4d89231fcff207ff2c13e4c24cde56.tar.gz | |
find and fix error in typesystem
| -rw-r--r-- | src/vm.rs | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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)]); |
