Allow empty ranges at the end of a sequence.

This commit is contained in:
Bob Nystrom
2015-12-06 10:37:58 -08:00
parent 10ece995f7
commit 6ff5fb9ff2
3 changed files with 14 additions and 5 deletions
+6 -5
View File
@@ -85,11 +85,12 @@ uint32_t calculateRange(WrenVM* vm, ObjRange* range, uint32_t* length,
{
*step = 0;
// Corner case: an empty range at zero is allowed on an empty sequence.
// This way, list[0..-1] and list[0...list.count] can be used to copy a list
// even when empty.
if (*length == 0 && range->from == 0 &&
range->to == (range->isInclusive ? -1 : 0)) {
// Edge case: an empty range is allowed at the end of a sequence. This way,
// list[0..-1] and list[0...list.count] can be used to copy a list even when
// empty.
if (range->from == *length &&
range->to == (range->isInclusive ? -1.0 : (double)*length)) {
*length = 0;
return 0;
}