rascal icon indicating copy to clipboard operation
rascal copied to clipboard

List assignable with negative index throws Java ArrayIndexOutOfBoundsException or Rascal IndexOutOfBounds

Open tvdstorm opened this issue 1 year ago • 1 comments

Reproduce:

rascal>list[tuple[int,int]] lst = [<1,2>];
lrel[int,int]: [<1,2>]
rascal>lst[-1]
tuple[int,int]: <1,2>
rascal>lst[-1][0] = 3;
java.lang.ArrayIndexOutOfBoundsException: -1 < 0
(internal error)
        at $shell$(|main://$shell$|)

java.lang.ArrayIndexOutOfBoundsException: -1 < 0
        at io.usethesource.vallang.util.ShareableList.get(ShareableList.java:396)
        at io.usethesource.vallang.impl.persistent.List.get(List.java:81)
        at org.rascalmpl.semantics.dynamic.Assignable$Subscript.interpret(Assignable.java:607)
        at org.rascalmpl.semantics.dynamic.Assignable$Subscript.assignment(Assignable.java:449)
        at org.rascalmpl.semantics.dynamic.Statement$Assignment.interpret(Statement.java:209)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:876)
        at org.rascalmpl.semantics.dynamic.Command$Statement.interpret(Command.java:125)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:1094)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:955)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:908)
        at org.rascalmpl.repl.RascalInterpreterREPL.evalStatement(RascalInterpreterREPL.java:132)
        at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL$1.evalStatement(LSPTerminalREPL.java:161)
        at org.rascalmpl.repl.BaseRascalREPL.handleInput(BaseRascalREPL.java:106)
        at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL$1.handleInput(LSPTerminalREPL.java:263)
        at org.rascalmpl.repl.BaseREPL.handleInput(BaseREPL.java:180)
        at org.rascalmpl.repl.BaseREPL.run(BaseREPL.java:347)
        at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL.main(LSPTerminalREPL.java:345)

When there's not a nested assignable (the tuple above) the error is different:

rascal>l2 = [1,2,3];
list[int]: [1,2,3]
rascal>l2[-1] = 5;
|prompt:///|(4,1,<1,4>,<1,5>): IndexOutOfBounds(-1)
        at $shell$(|main://$shell$|ok
rascal>l2[-1]
int: 3

tvdstorm avatar Jan 04 '24 13:01 tvdstorm

It would be the latter behavior indeed. Good catch!

jurgenvinju avatar Jan 05 '24 17:01 jurgenvinju