Skip to content

Commit 985116a

Browse files
committed
patch 8.2.1191: Vim9: crash when function calls itself
Problem: Vim9: crash when function calls itself. Solution: Add status UF_COMPILING. (closes #6441)
1 parent eb6880b commit 985116a

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

src/structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1539,6 +1539,7 @@ typedef struct funccall_S funccall_T;
15391539
typedef enum {
15401540
UF_NOT_COMPILED,
15411541
UF_TO_BE_COMPILED,
1542+
UF_COMPILING,
15421543
UF_COMPILED
15431544
} def_status_T;
15441545

src/testdir/test_vim9_func.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,5 +999,17 @@ func Test_silent_echo()
999999
call delete('XTest_silent_echo')
10001000
endfunc
10011001

1002+
def Fibonacci(n: number): number
1003+
if n < 2
1004+
return n
1005+
else
1006+
return Fibonacci(n - 1) + Fibonacci(n - 2)
1007+
endif
1008+
enddef
1009+
1010+
def Test_recursive_call()
1011+
assert_equal(6765, Fibonacci(20))
1012+
enddef
1013+
10021014

10031015
" vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1191,
757759
/**/
758760
1190,
759761
/**/

src/vim9compile.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6802,6 +6802,8 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
68026802
else if (add_def_function(ufunc) == FAIL)
68036803
return FAIL;
68046804

6805+
ufunc->uf_def_status = UF_COMPILING;
6806+
68056807
CLEAR_FIELD(cctx);
68066808
cctx.ctx_ufunc = ufunc;
68076809
cctx.ctx_lnum = -1;

0 commit comments

Comments
 (0)