]> granicus.if.org Git - vim/commitdiff
patch 8.2.1191: Vim9: crash when function calls itself v8.2.1191
authorBram Moolenaar <Bram@vim.org>
Sun, 12 Jul 2020 15:31:09 +0000 (17:31 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 12 Jul 2020 15:31:09 +0000 (17:31 +0200)
Problem:    Vim9: crash when function calls itself.
Solution:   Add status UF_COMPILING. (closes #6441)

src/structs.h
src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index bdc763b52d97d5e98b6f9b0e20e7ab2082ddd2db..4a0c10a459e5419dde4dacef44cb9f48b25b9f91 100644 (file)
@@ -1539,6 +1539,7 @@ typedef struct funccall_S funccall_T;
 typedef enum {
     UF_NOT_COMPILED,
     UF_TO_BE_COMPILED,
+    UF_COMPILING,
     UF_COMPILED
 } def_status_T;
 
index 5ea29457ee97cf5f53115545c2cb21b2ecff8361..53206dfb7be90ef46f2c85fd47f84a5806d6d348 100644 (file)
@@ -999,5 +999,17 @@ func Test_silent_echo()
   call delete('XTest_silent_echo')
 endfunc
 
+def Fibonacci(n: number): number
+  if n < 2
+    return n
+  else
+    return Fibonacci(n - 1) + Fibonacci(n - 2)
+  endif
+enddef
+
+def Test_recursive_call()
+  assert_equal(6765, Fibonacci(20))
+enddef
+
 
 " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
index 8ae2f29d58d664ed3d03b2ef26bcbc6ba4165008..487303edc92c7f5b4209e3742b0a4bf3cf28ec80 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1191,
 /**/
     1190,
 /**/
index fceb4811bc4b7af091a62bb8d0332faf28f9ddd4..8d6c1398dad133bf15d608cc3cbd2cd2dd2a6d2c 100644 (file)
@@ -6802,6 +6802,8 @@ compile_def_function(ufunc_T *ufunc, int set_return_type, cctx_T *outer_cctx)
     else if (add_def_function(ufunc) == FAIL)
        return FAIL;
 
+    ufunc->uf_def_status = UF_COMPILING;
+
     CLEAR_FIELD(cctx);
     cctx.ctx_ufunc = ufunc;
     cctx.ctx_lnum = -1;