Skip to content

Commit 2bbd3eb

Browse files
committed
FIX: catch/quit/name catches only quit or halt, but not any named throw
resolves: Oldes/Rebol-issues#2549
1 parent 0605fd5 commit 2bbd3eb

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

make/tools/make-headers.reb

+1
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ context [
319319
checksum
320320
request-file
321321
request-dir
322+
catch
322323
] [make-arg-enums word]
323324

324325
;?? output

src/core/n-control.c

+13-11
Original file line numberDiff line numberDiff line change
@@ -413,13 +413,15 @@ enum {
413413
REBVAL *val;
414414
REBVAL *ret;
415415
REBCNT sym;
416-
REBVAL recover = *D_ARG(6);
416+
REBVAL recover = *D_ARG(AM_CATCH_RECOVER);
417417
REBVAL *last_result = Get_System(SYS_STATE, STATE_LAST_RESULT);
418+
REBOOL quit;
418419

419-
if (D_REF(4)) { //QUIT
420-
if (Try_Block_Halt(VAL_SERIES(D_ARG(1)), VAL_INDEX(D_ARG(1)))) {
420+
if (D_REF(AM_CATCH_QUIT)) { //QUIT
421+
quit = Try_Block_Halt(VAL_SERIES(D_ARG(AM_CATCH_BLOCK)), VAL_INDEX(D_ARG(AM_CATCH_BLOCK)));
422+
ret = DS_NEXT;
423+
if (quit) {
421424
// We are here because of a QUIT or HALT condition.
422-
ret = DS_NEXT;
423425
if (VAL_ERR_NUM(ret) == RE_QUIT)
424426
ret = VAL_ERR_VALUE(ret);
425427
else if (VAL_ERR_NUM(ret) == RE_HALT)
@@ -435,20 +437,20 @@ enum {
435437
*DS_RETURN = *ret;
436438
return R_RET;
437439
}
438-
return R_TOS1;
439-
}
440-
441-
// Evaluate the block:
442-
ret = DO_BLK(D_ARG(1));
440+
if (!D_REF(AM_CATCH_NAME)) return R_TOS1;
441+
} else {
442+
// Evaluate the block:
443+
ret = DO_BLK(D_ARG(AM_CATCH_BLOCK));
444+
}
443445

444446
// If it is a throw, process it:
445447
if (IS_ERROR(ret) && VAL_ERR_NUM(ret) == RE_THROW) {
446448

447449
// If a named throw, then check it:
448-
if (D_REF(2)) { // /name
450+
if (D_REF(AM_CATCH_NAME)) { // /name
449451

450452
sym = VAL_ERR_SYM(ret);
451-
val = D_ARG(3); // name symbol
453+
val = D_ARG(AM_CATCH_WORD); // name symbol
452454

453455
// If name is the same word:
454456
if (IS_WORD(val) && sym == VAL_WORD_CANON(val)) goto got_err;

src/tests/units/evaluation-test.r3

+7
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,13 @@ Rebol [
777777
--assert 3 = catch/recover [a: 1 throw 3 a: 2][a: system/state/last-result a: a * 10]
778778
--assert a = 30
779779

780+
--test-- "catch/quit/name"
781+
;@@ https://github.com/Oldes/Rebol-issues/issues/2549
782+
--assert all [
783+
'foo = catch/quit/name [a: 1 throw/name 'foo 'name a: 2] 'name
784+
a = 1
785+
]
786+
780787

781788
===end-group===
782789

0 commit comments

Comments
 (0)