Skip to content

Commit f229de6

Browse files
committed
FIX: transcode/error of an invalid serialized constructor triggers the error it should insert
resolves: Oldes/Rebol-issues#1857
1 parent 07cd99d commit f229de6

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

src/core/l-scan.c

+14-5
Original file line numberDiff line numberDiff line change
@@ -1661,12 +1661,20 @@ extern REBSER *Scan_Full_Block(SCAN_STATE *scan_state, REBYTE mode_char);
16611661
case TOKEN_CONSTRUCT:
16621662
block = Scan_Full_Block(scan_state, ']');
16631663
value = BLK_TAIL(emitbuf);
1664-
emitbuf->tail++; // Protect the block from GC
1665-
if (!Construct_Value(value, block)) {
1666-
if (IS_END(value)) Set_Block(value, block);
1667-
Trap1(RE_MALCONSTRUCT, value);
1664+
// make sure that there was not an error... transcode "#["
1665+
if (!IS_ERROR(value)){
1666+
emitbuf->tail++; // Protect the block from GC
1667+
if (!Construct_Value(value, block)) {
1668+
if (IS_END(value)) Set_Block(value, block);
1669+
if (GET_FLAG(scan_state->opts, SCAN_RELAX)) {
1670+
block = Make_Error(RE_MALCONSTRUCT, value, 0, 0);
1671+
SET_ERROR(value, RE_PAST_END, block);
1672+
} else {
1673+
Trap1(RE_MALCONSTRUCT, value);
1674+
}
1675+
}
1676+
emitbuf->tail--; // Unprotect
16681677
}
1669-
emitbuf->tail--; // Unprotect
16701678
break;
16711679

16721680
case TOKEN_MAP:
@@ -1720,6 +1728,7 @@ extern REBSER *Scan_Full_Block(SCAN_STATE *scan_state, REBYTE mode_char);
17201728
goto exit_block;
17211729
}
17221730
}
1731+
17231732

17241733
// Check for end of path:
17251734
if (mode_char == '/') {

src/tests/units/lexer-test.r3

+23
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ Rebol [
4949
value = 2 line = 2
5050
]
5151

52+
--test-- "transcode/error"
53+
--assert all [
54+
block? blk: transcode/error "1 2d"
55+
blk/1 = 1
56+
error? blk/2
57+
blk/2/id = 'invalid
58+
]
59+
;@@ https://github.com/Oldes/Rebol-issues/issues/1857
60+
--assert all [
61+
error? e: transcode/one/error "#[block! 1]"
62+
e/id = 'malconstruct
63+
]
64+
--assert all [
65+
error? e: transcode/one/error "#[block! [1d]"
66+
e/id = 'malconstruct
67+
]
68+
--assert all [
69+
error? e: transcode/one/error "#["
70+
e/id = 'missing
71+
e/arg1 = 'end-of-script
72+
]
73+
74+
5275
===end-group===
5376

5477
===start-group=== "Invalid construction"

0 commit comments

Comments
 (0)