diff src/testdir/test_lambda.vim @ 9721:79862f44c647 v7.4.2136

commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a Author: Bram Moolenaar <Bram@vim.org> Date: Sun Jul 31 18:30:22 2016 +0200 patch 7.4.2136 Problem: Closure function fails. Solution: Don't reset uf_scoped when it points to another funccal.
author Christian Brabandt <cb@256bit.org>
date Sun, 31 Jul 2016 18:45:06 +0200
parents 4a7a88404076
children 80ac9cf77c9b
line wrap: on
line diff
--- a/src/testdir/test_lambda.vim
+++ b/src/testdir/test_lambda.vim
@@ -247,3 +247,27 @@ function! Test_closure_unlet()
   call assert_false(has_key(s:foo(), 'x'))
   call test_garbagecollect_now()
 endfunction
+
+function! LambdaFoo()
+  let x = 0
+  function! LambdaBar() closure
+    let x += 1
+    return x
+  endfunction
+  return function('LambdaBar')
+endfunction
+
+func Test_closure_refcount()
+  let g:Count = LambdaFoo()
+  call test_garbagecollect_now()
+  call assert_equal(1, g:Count())
+  let g:Count2 = LambdaFoo()
+  call test_garbagecollect_now()
+  call assert_equal(1, g:Count2())
+  call assert_equal(2, g:Count())
+  call assert_equal(3, g:Count2())
+
+  " This causes memory access errors.
+  " delfunc LambdaFoo
+  " delfunc LambdaBar
+endfunc