From 84293975eced8a2815707e6702913b215a4c662e Mon Sep 17 00:00:00 2001 From: Oldes Date: Wed, 21 Jun 2023 10:34:03 +0200 Subject: [PATCH] FIX: MAKE ERROR! does not process THROWN values as THROWN resolves: https://github.com/Oldes/Rebol-issues/issues/2244 --- src/core/c-error.c | 9 ++++++++- src/tests/units/evaluation-test.r3 | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/c-error.c b/src/core/c-error.c index 1b1873b142..04f6b0b84a 100644 --- a/src/core/c-error.c +++ b/src/core/c-error.c @@ -356,6 +356,7 @@ static REBOL_STATE Top_State; // Boot var: holds error state during boot REBSER *err; // Error object ERROR_OBJ *error; // Error object values REBINT code = 0; + REBVAL *tmp; // Create a new error object from another object, including any non-standard fields: if (IS_ERROR(arg) || IS_OBJECT(arg)) { @@ -380,8 +381,14 @@ static REBOL_STATE Top_State; // Boot var: holds error state during boot // If user set error code, use it to setup type and id fields. if (IS_BLOCK(arg)) { DISABLE_GC; - Do_Bind_Block(err, arg); // GC-OK (disabled) + tmp = Do_Bind_Block(err, arg); // GC-OK (disabled) ENABLE_GC; + if (THROWN(tmp)) { + *value = *tmp; + return; + } + + //It was possible to set error using code, but that's now ignored! //@@ https://github.com/Oldes/Rebol-issues/issues/1593 //if (IS_INTEGER(&error->code) && VAL_INT64(&error->code)) { diff --git a/src/tests/units/evaluation-test.r3 b/src/tests/units/evaluation-test.r3 index 7fbd9780a2..39d799c925 100644 --- a/src/tests/units/evaluation-test.r3 +++ b/src/tests/units/evaluation-test.r3 @@ -799,6 +799,11 @@ Rebol [ --assert 1 = catch/all [a: 0 catch/name [++ a throw/name 1 'foo] 'bar a: a * 10] --assert 1 = a + --test-- "throw from make error!" + ;@@ https://github.com/Oldes/Rebol-issues/issues/2244 + --assert error? catch [make error! [type: 'Access arg1: 10 + 20 id: 'Protocol]] + --assert 30 = catch [make error! [type: 'Access arg1: throw 10 + 20 id: 'Protocol]] + ===end-group===