Skip to content

Commit

Permalink
FIX: fixed regression with break in a reduce block
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Sep 5, 2022
1 parent 249f1be commit 1150994
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/core/n-control.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ enum {
{
if (ANY_SERIES(value) || IS_MAP(value) || IS_BITSET(value))
Protect_Series(value, flags);
else if (IS_OBJECT(value) || IS_MODULE(value))
else if (ANY_OBJECT(value))
Protect_Object(value, flags);
}

Expand Down Expand Up @@ -741,8 +741,9 @@ enum {
{
REBVAL *val = D_ARG(1);
REBVAL *into = D_REF(5) ? D_ARG(6) : 0;
REBCNT type = VAL_TYPE(val);

if (IS_BLOCK(val) || IS_PAREN(val)) {
if (type == REB_BLOCK || type == REB_PAREN) {
REBSER *ser = VAL_SERIES(val);
REBCNT index = VAL_INDEX(val);

Expand All @@ -753,9 +754,12 @@ enum {
else
Reduce_Block(ser, index, into);

if(!into)
SET_TYPE(DS_TOP, VAL_TYPE(val));

if (type == REB_PAREN)
// there must be also test, if the result is a block,
// because it can be also THROWN! see issue-1760
if (!into && IS_BLOCK(DS_TOP))
SET_TYPE(DS_TOP, REB_PAREN);

return R_TOS;
}
else if (into != 0) {
Expand Down Expand Up @@ -809,12 +813,11 @@ enum {
REBVAL *blk = VAL_BLK_DATA(D_ARG(2));
REBVAL *result;
REBOOL all = D_REF(5);
REBOOL is_case = D_REF(6);
REBOOL found = FALSE;

// Find value in case block...
for (; NOT_END(blk); blk++) {
if (!IS_BLOCK(blk) && 0 == Cmp_Value(DS_ARG(1), blk, is_case)) { // avoid stack move
if (!IS_BLOCK(blk) && 0 == Cmp_Value(DS_ARG(1), blk, FALSE)) { // avoid stack move
// Skip forward to block...
for (; !IS_BLOCK(blk) && NOT_END(blk); blk++);
if (IS_END(blk)) break;
Expand Down
3 changes: 3 additions & 0 deletions src/tests/units/evaluation-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,9 @@ Rebol [
--assert :a =? 1
a: 1 loop 1 [a: compose [(break)]]
--assert :a =? 1
;@@ https://github.com/Oldes/Rebol-issues/issues/2060
a: 1 loop 1 [a: reduce quote (break)]
--assert :a =? 1

===end-group===

Expand Down

0 comments on commit 1150994

Please sign in to comment.