robpike / ivy

ivy, an APL-like calculator
Other
1.32k stars 103 forks source link

ivy: fix function undefinition #140

Closed yishailerner closed 1 year ago

yishailerner commented 1 year ago

Function undefinition did not work because the previous definition was overwritten before being saved, and so restoring it was a no-op.

This meant functions with intermediate state could be produced, potentially violating invariants. For example, the following creates a function with a partial body but without any locals, eventually leading to an index out of range when trying to access the local b:

op inc b =
  b + 1
  |

inc 1
$ ivy <crash.ivy
unexpected EOF

panic: runtime error: index out of range [-1] [recovered]
        panic: runtime error: index out of range [-1]

goroutine 1 [running]:
...
robpike commented 1 year ago

Nice catch, thanks.