Skip to content

Conversation

@jbdoderlein
Copy link
Contributor

This PR fix a java.lang.ArrayIndexOutOfBoundsException exception when using negative index in nested list assignement.

The bug :

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

java.lang.ArrayIndexOutOfBoundsException: -1 < 0
        at io.usethesource.vallang.util.ShareableList.get(ShareableList.java:398)
        at io.usethesource.vallang.impl.persistent.List.get(List.java:81)
        at org.rascalmpl.semantics.dynamic.Assignable$Subscript.interpret(Assignable.java:610)
        at org.rascalmpl.semantics.dynamic.Assignable$Subscript.assignment(Assignable.java:449)
        at org.rascalmpl.semantics.dynamic.Statement$Assignment.interpret(Statement.java:227)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:830)
        at org.rascalmpl.semantics.dynamic.Command$Statement.interpret(Command.java:126)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:1066)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:915)
        at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:866)
        at org.rascalmpl.repl.rascal.RascalInterpreterREPL.handleInput(RascalInterpreterREPL.java:236)
        at org.rascalmpl.repl.rascal.RascalReplServices.handleInput(RascalReplServices.java:109)
        at org.rascalmpl.repl.BaseREPL.handleInput(BaseREPL.java:217)
        at org.rascalmpl.repl.BaseREPL.run(BaseREPL.java:134)
        at org.rascalmpl.shell.REPLRunner.run(REPLRunner.java:30)
        at org.rascalmpl.shell.RascalShell.main(RascalShell.java:65)
        at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL.main(LSPTerminalREPL.java:59)

With the PR :

rascal>var1 = [[0],[1]];
list[list[int]]: [
  [0],
  [1]
]
rascal>var1[-1][-1]
int: 1
rascal>var1[-1][-1] = 3;
list[list[int]]: [
  [0],
  [3]
]

@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46%. Comparing base (726cd6d) to head (68a7594).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##              main   #2587   +/-   ##
=======================================
  Coverage       46%     46%           
- Complexity    6632    6633    +1     
=======================================
  Files          793     793           
  Lines        65584   65586    +2     
  Branches      9822    9823    +1     
=======================================
+ Hits         30486   30493    +7     
+ Misses       32748   32743    -5     
  Partials      2350    2350           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DavyLandman
Copy link
Member

Did you take this discussion into account? #2370 (comment)

@jbdoderlein jbdoderlein force-pushed the fix-negative-index-assignement branch from 8dc6e38 to 4bdd971 Compare January 7, 2026 17:46
@jbdoderlein
Copy link
Contributor Author

Ok i didn't know about this issue. This is not the same issue but it is related.

Taking into account the documentation, there is missing IndexOutOfBound throw in the slicing method, I think I will try to open a new PR to fix these tomorrow.

@DavyLandman
Copy link
Member

Would it be possible to add a small rascal unit test, just so that we never have a regression on this? (or the compiler might be sensative to this).

The lang::rascal::tests::basic::Lists would be the best place for this.

@DavyLandman DavyLandman merged commit 3cc9359 into usethesource:main Jan 8, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants