Skip to content

Commit d1ff72d

Browse files
committed
FIX: crash when using context? on function's local word outside of its function
resolves: Oldes/Rebol-issues#2440 related to: Oldes/Rebol-issues#886
1 parent c756498 commit d1ff72d

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/core/n-data.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -339,8 +339,17 @@ static int Check_Char_Range(REBVAL *val, REBINT limit)
339339

340340
if (!HAS_FRAME(word)) return R_NONE;
341341
if (VAL_WORD_INDEX(word) < 0) {
342-
// was originally returning R_TRUE for function context
343-
*D_RET = Stack_Frame(1)[3];
342+
// was originally returning R_TRUE for all function contexts
343+
// we can try to resolve the function from stack (VAL_WORD_FRAME is not valid in this case)
344+
REBVAL *frame = Stack_Frame(1);
345+
// if there was no frame on the stack, the word is a leaked local of some function
346+
// and it looks there is no way how to resolve it, so return NONE
347+
if (!frame)
348+
// this is in case like ` f: func[a][p: 'a] f 1 context? p `
349+
return R_NONE;
350+
// else return function spec
351+
// case like: ` f: func[a][context? 'a] f 1 `
352+
*D_RET = frame[3];
344353
} else {
345354
SET_OBJECT(D_RET, VAL_WORD_FRAME(word));
346355
}

src/tests/units/func-test.r3

+8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@ Rebol [
7878
f2 arg1
7979
]
8080
--assert [a] = f 1 2
81+
82+
;@@ https://github.com/Oldes/Rebol-issues/issues/886
83+
f: func[arg][p: 'arg]
84+
f 1 2
85+
--assert none? context? p ; and no crash!
86+
87+
c: closure[a][context? 'a]
88+
--assert all [object? o: c 1 o/a = 1]
8189
===end-group===
8290

8391

0 commit comments

Comments
 (0)