Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/org/rascalmpl/library/lang/rascal/tests/basic/Lists.rsc
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ test bool AssignFromEnd1(){ L = [0,1,2,3,4,5,6,7,8,9]; L[-1] = 90; return L ==
test bool AssignFromEnd2(){ L = [0,1,2,3,4,5,6,7,8,9]; L[-2] = 80; return L == [0,1,2,3,4,5,6,7,80,9]; }
test bool AssignFromEnd3(){ L = [0,1,2,3,4,5,6,7,8,9]; L[-10] = 10; return L == [10,1,2,3,4,5,6,7,8,9]; }

// Nested Lists

test bool AssignNestedList1(){ L = [[0,1,2],[3,4,5],[6,7,8,9]]; L[1][2] = 50; return L == [[0,1,2],[3,4,50],[6,7,8,9]]; }
test bool AccessNestedList1(){ L = [[0,1,2],[3,4,5],[6,7,8,9]]; return L[1][2] == 5; }
test bool AssignNestedList2(){ L = [[0,1,2],[3,4,5],[6,7,8,9]]; L[-2][-1] = 50; return L == [[0,1,2],[3,4,50],[6,7,8,9]]; }
test bool AccessNestedList2(){ L = [[0,1,2],[3,4,5],[6,7,8,9]]; return L[-2][-1] == 5; }

// Library functions

test bool tstDelete(list[&T] L) {
Expand Down
7 changes: 5 additions & 2 deletions src/org/rascalmpl/semantics/dynamic/Assignable.java
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,11 @@ public Result<IValue> interpret(IEvaluator<Result<IValue>> __eval) {
if (receiver.getStaticType().isList()) {
if (subscript.getStaticType().isInteger()) {
IList list = (IList) receiver.getValue();
IValue result = list.get(((IInteger) subscript.getValue())
.intValue());
int index = ((IInteger) subscript.getValue()).intValue();
if (index < 0) {
index += list.length();
}
IValue result = list.get(index);
Type type = receiver.getStaticType().getElementType();
return normalizedResult(__eval, type, result);
}
Expand Down
Loading