Commit 1136c431 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #125 from jvkersch/fix-tuple-indexing

Fix negative indexing issue.
parents eb72b555 7f054c03
......@@ -70,11 +70,9 @@ Box* tupleGetitemInt(BoxedTuple* self, BoxedInt* slice) {
i64 size = self->elts.size();
if (n < 0)
n = size - n;
if (n < 0 || n >= size) {
fprintf(stderr, "IndexError: tuple index out of range\n");
raiseExcHelper(IndexError, "");
}
n = size + n;
if (n < 0 || n >= size)
raiseExcHelper(IndexError, "tuple index out of range");
Box* rtn = self->elts[n];
return rtn;
......
......@@ -153,3 +153,18 @@ try:
t[(1, 2)]
except TypeError as e:
print e
# Single element indexing.
t = (1, None, "abc")
for n in range(-3, 3):
print t[n]
try:
t[-4]
except IndexError as e:
print e
try:
t[3]
except IndexError as e:
print e
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment