rascal
rascal copied to clipboard
Tuple projection throws `java.lang.ArrayIndexOutOfBoundsException` when the field index equals the tuple length
Describe the bug
Tuple projection throws java.lang.ArrayIndexOutOfBoundsException when the field index equals the tuple length.
To Reproduce
rascal><"foo", "bar"><0>;
str: "foo"
rascal><"foo", "bar"><1>;
str: "bar"
rascal><"foo", "bar"><2>;
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
(internal error)
at $shell$(|main://$shell$|)
rascal><"foo", "bar"><3>;
|prompt:///|(8,5,<1,8>,<1,13>): IndexOutOfBounds(3)
at $shell$(|prompt:///|(0,18,<1,0>,<1,18>)
rascal><"foo", "bar"><1000>;
|prompt:///|(8,5,<1,8>,<1,13>): IndexOutOfBounds(1000)
at $shell$(|prompt:///|(0,21,<1,0>,<1,21>)
Expected behavior
rascal><"foo", "bar"><2>;
|prompt:///|(8,5,<1,8>,<1,13>): IndexOutOfBounds(2)
at $shell$(|prompt:///|(0,18,<1,0>,<1,18>)
Stack traces
java.lang.ArrayIndexOutOfBoundsException: Index 2 out of bounds for length 2
at io.usethesource.vallang.type.TupleType.getFieldType(TupleType.java:131)
at io.usethesource.vallang.type.TupleType.select(TupleType.java:450)
at org.rascalmpl.interpreter.result.TupleResult.fieldSelect(TupleResult.java:52)
at org.rascalmpl.interpreter.result.TupleResult.fieldSelect(TupleResult.java:114)
at org.rascalmpl.semantics.dynamic.Expression$FieldProject.interpret(Expression.java:907)
at org.rascalmpl.semantics.dynamic.Statement$Expression.interpret(Statement.java:365)
at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:899)
at org.rascalmpl.semantics.dynamic.Command$Statement.interpret(Command.java:125)
at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:1135)
at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:984)
at org.rascalmpl.interpreter.Evaluator.eval(Evaluator.java:935)
at org.rascalmpl.repl.RascalInterpreterREPL.evalStatement(RascalInterpreterREPL.java:134)
at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL$1.evalStatement(LSPTerminalREPL.java:137)
at org.rascalmpl.repl.BaseRascalREPL.handleInput(BaseRascalREPL.java:107)
at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL$1.handleInput(LSPTerminalREPL.java:233)
at org.rascalmpl.repl.BaseREPL.handleInput(BaseREPL.java:179)
at org.rascalmpl.repl.BaseREPL.run(BaseREPL.java:346)
at org.rascalmpl.vscode.lsp.terminal.LSPTerminalREPL.main(LSPTerminalREPL.java:320)