annotate src/testdir/test_nested_function.vim @ 10381:14a82c6433be v8.0.0085

commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924 Author: Bram Moolenaar <Bram@vim.org> Date: Mon Nov 14 21:50:00 2016 +0100 patch 8.0.0085 Problem: Using freed memory with recursive function call. (Dominique Pelle) Solution: Make a copy of the function name.
author Christian Brabandt <cb@256bit.org>
date Mon, 14 Nov 2016 22:00:04 +0100
parents c577c6a2e88b
children 89200fa1d174
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 "Tests for nested functions
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 "
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
3 func NestedFunc()
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
4 func! Func1()
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 let g:text .= 'Func1 '
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
6 endfunc
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 call Func1()
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
8 func! s:func2()
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 let g:text .= 's:func2 '
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
10 endfunc
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 call s:func2()
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
12 func! s:_func3()
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 let g:text .= 's:_func3 '
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
14 endfunc
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 call s:_func3()
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 let fn = 'Func4'
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
17 func! {fn}()
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 let g:text .= 'Func4 '
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
19 endfunc
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 call {fn}()
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 let fn = 'func5'
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
22 func! s:{fn}()
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 let g:text .= 's:func5'
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
24 endfunc
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25 call s:{fn}()
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
26 endfunc
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
28 func Test_nested_functions()
10068
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 let g:text = ''
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 call NestedFunc()
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 call assert_equal('Func1 s:func2 s:_func3 Func4 s:func5', g:text)
c577c6a2e88b commit https://github.com/vim/vim/commit/19a1669ffc796e30a83c5600f82f12ebf63a2261
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 endfunction
10381
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
33
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
34 func Test_nested_argument()
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
35 func g:X()
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
36 let g:Y = function('sort')
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
37 endfunc
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
38 let g:Y = function('sort')
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
39 echo g:Y([], g:X())
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
40 delfunc g:X
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
41 unlet g:Y
14a82c6433be commit https://github.com/vim/vim/commit/8a01f969c198eeb655ad2f96f2796a6f6f4a1924
Christian Brabandt <cb@256bit.org>
parents: 10068
diff changeset
42 endfunc