V version: : V 0.1.11
OS: : Ubuntu 18.04
What did you do?
mask@petronav:~$ v
V 0.1.11
Use Ctrl-D or `exit` to exit
For now you have to use println() to print values, this will be fixed soon
>>> a := [1,2,3]
>>> println(a[-1])
V panic: array index out of range: -1/3
>>> println(a.len)
V panic: array index out of range: -1/3
>>> ^Z
[1]+ Stopped v
mask@petronav:~$ v
V 0.1.11
Use Ctrl-D or `exit` to exit
For now you have to use println() to print values, this will be fixed soon
>>> a := [1,2,3]
>>> println(a.len)
3
>>>
What did you expect to see and what did you see instead?
First time when I do println(a.len) after println(a[-1]) line it should have printed 3 but in stead it shows V panic.
Your version is way behind the current 0.1.11
Do a git pull
and make then try running the file
Also make sure to remove the previous link to your v executable after you compile.
@Glitchfix I've updated version but this same bug is also occurring for version 0.1.11
I don't know how the interpreter works nowadays, but if it still writes everything to a file and compiles it, a workaround would be to check if the last input produced an error, and if it did, remove it from the temporary file.
@petronav It's actually a repl issue I'm trying to fix it. Stay tuned.
@petronav would you like to see if this could solve your problem https://github.com/vlang/v/pull/962
@petronav Seems to be working at the moment.
a[-1] results in a panic in V, negative array index is not supported, unlike in Python.
Most helpful comment
@petronav It's actually a repl issue I'm trying to fix it. Stay tuned.