Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List assignable with negative index throws Java ArrayIndexOutOfBoundsException or Rascal IndexOutOfBounds #1903

Open
tvdstorm opened this issue Jan 4, 2024 · 1 comment

Comments

@tvdstorm
Copy link
Member

tvdstorm commented Jan 4, 2024

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
@jurgenvinju
Copy link
Member

It would be the latter behavior indeed. Good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants