Mercurial > vim
comparison src/testdir/test_vim9_func.vim @ 28173:b0c885507de4 v8.2.4612
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Commit: https://github.com/vim/vim/commit/a915fa010330ee7212e06d3511acd363d04d2d28
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Mar 23 11:29:15 2022 +0000
patch 8.2.4612: Vim9: cannot use a recursive call in a nested function
Problem: Vim9: cannot use a recursive call in a nested function. (Sergey
Vlasov)
Solution: Define the funcref before compiling the function. (closes #9989)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 23 Mar 2022 12:30:04 +0100 |
parents | ae975c8d5438 |
children | f24d4826e6bf |
comparison
equal
deleted
inserted
replaced
28172:f5cd730da5b6 | 28173:b0c885507de4 |
---|---|
871 enddef | 871 enddef |
872 endif | 872 endif |
873 defcompile | 873 defcompile |
874 assert_equal(1, Test()) | 874 assert_equal(1, Test()) |
875 assert_equal(2, Test()) | 875 assert_equal(2, Test()) |
876 END | |
877 v9.CheckScriptSuccess(lines) | |
878 | |
879 # nested function with recursive call | |
880 lines =<< trim END | |
881 vim9script | |
882 | |
883 def MyFunc(): number | |
884 def Fib(n: number): number | |
885 if n < 2 | |
886 return 1 | |
887 endif | |
888 return Fib(n - 2) + Fib(n - 1) | |
889 enddef | |
890 | |
891 return Fib(5) | |
892 enddef | |
893 | |
894 assert_equal(8, MyFunc()) | |
876 END | 895 END |
877 v9.CheckScriptSuccess(lines) | 896 v9.CheckScriptSuccess(lines) |
878 | 897 |
879 lines =<< trim END | 898 lines =<< trim END |
880 vim9script | 899 vim9script |