Skip to content

Commit 7af6ebe

Browse files
committed
FIX: crash when using foreach with a set-word and values not in a block
resolves: Oldes/Rebol-issues#2530
1 parent 1265b8b commit 7af6ebe

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/core/n-loop.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
** REBOL [R3] Language Interpreter and Run-time Environment
44
**
55
** Copyright 2012 REBOL Technologies
6+
** Copyright 2012-2023 Rebol Open Source Developers
67
** REBOL is a trademark of REBOL Technologies
78
**
89
** Licensed under the Apache License, Version 2.0 (the "License");
@@ -443,7 +444,7 @@ enum loop_each_mode {
443444
if (ANY_OBJECT(value) || IS_MAP(value)) {
444445
*vars = *value;
445446
} else {
446-
VAL_SET(vars, REB_BLOCK);
447+
VAL_SET(vars, VAL_TYPE(value));
447448
VAL_SERIES(vars) = series;
448449
VAL_INDEX(vars) = index;
449450
}

src/tests/units/series-test.r3

+15
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,21 @@ Rebol [
15241524
--assert 3 = foreach [ref: k v] m [if ref = m [x: x + v]]
15251525
--assert 6 = foreach [ref: k] m [if ref = m [x: x + m/:k]]
15261526
--assert ref = 'foo
1527+
1528+
--test-- "FOREACH [ref:] series!"
1529+
;@@ https://github.com/Oldes/Rebol-issues/issues/2530
1530+
code: [if 2 = index? ref [break/return ref]]
1531+
foreach [result values][
1532+
[2] [1 2]
1533+
(2) (1 2)
1534+
b/c a/b/c
1535+
"bc" "abc"
1536+
%bc %abc
1537+
#{02} #{0102}
1538+
][
1539+
--assert result == foreach [ref:] :values :code
1540+
]
1541+
15271542
===end-group===
15281543

15291544
===start-group=== "MAP-EACH"

0 commit comments

Comments
 (0)