Skip to content

Commit 0bb90c5

Browse files
committed
FIX: POKE into vector! does not throw out of range error
fixes: Oldes/Rebol-issues#2427
1 parent da2798a commit 0bb90c5

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/core/c-do.c

+3
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,9 @@ void Trace_Arg(REBINT num, REBVAL *arg, REBVAL *path)
549549
case PE_BAD_SET:
550550
Trap2(RE_BAD_PATH_SET, pvs.value, pvs.select);
551551
break;
552+
case PE_BAD_RANGE:
553+
Trap_Range(selector);
554+
break;
552555
}
553556
}
554557

src/core/t-vector.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ void Set_Vector_Row(REBSER *ser, REBVAL *blk)
618618

619619
if (IS_INTEGER(sel) || IS_DECIMAL(sel)) {
620620
n = Int32(sel);
621-
if (n == 0) return PE_NONE;
621+
if (n == 0) return (pvs->setval) ? PE_BAD_RANGE : PE_NONE; // allow PICK with zero index but not for POKE
622622
if (n < 0) n++;
623623
} else if (IS_WORD(sel)) {
624624
if (set == 0) {

src/tests/units/vector-test.r3

+20
Original file line numberDiff line numberDiff line change
@@ -399,4 +399,24 @@ Rebol [
399399
]
400400
===end-group===
401401

402+
403+
===start-group=== "POKE"
404+
--test-- "POKE into vector!"
405+
v: #[ui32! [1 2 3]]
406+
--assert all [
407+
10 = poke v 1 10
408+
10 = pick v 1
409+
]
410+
;@@ https://github.com/Oldes/Rebol-issues/issues/2427
411+
--assert all [
412+
error? err: try [poke v 10 1]
413+
err/id = 'out-of-range
414+
]
415+
--assert all [
416+
error? err: try [poke v 0 1]
417+
err/id = 'out-of-range
418+
]
419+
===end-group===
420+
421+
402422
~~~end-file~~~

0 commit comments

Comments
 (0)