Skip to content

Commit a763e28

Browse files
committed
refs leafo#347 - fixes negative index with set-nth() too
1 parent 12f27ee commit a763e28

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Compiler.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4233,7 +4233,13 @@ protected function libNth($args)
42334233
protected function libSetNth($args)
42344234
{
42354235
$list = $this->coerceList($args[0]);
4236-
$n = $this->assertNumber($args[1]) - 1;
4236+
$n = $this->assertNumber($args[1]);
4237+
4238+
if ($n > 0) {
4239+
$n--;
4240+
} elseif ($n < 0) {
4241+
$n += count($list[2]);
4242+
}
42374243

42384244
if (! isset($list[2][$n])) {
42394245
$this->throwError('Invalid argument for "n"');

0 commit comments

Comments
 (0)