summaryrefslogtreecommitdiffstats
path: root/src/testdir/test_vim9_script.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-10-15 20:42:20 +0200
committerBram Moolenaar <Bram@vim.org>2020-10-15 20:42:20 +0200
commited234f24f3a6d697ba9b786d0bc74d4682bfdf47 (patch)
tree52de9eabe6a57c76ff561d8a7fa5354af6fbb3e0 /src/testdir/test_vim9_script.vim
parent74f8eece5e481220e3c0767487c0bb59fa916ed6 (diff)
patch 8.2.1849: Vim9: garbage collection frees block-local variablesv8.2.1849
Problem: Vim9: garbage collection frees block-local variables. Solution: Mark all script variables as used.
Diffstat (limited to 'src/testdir/test_vim9_script.vim')
-rw-r--r--src/testdir/test_vim9_script.vim34
1 files changed, 25 insertions, 9 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim
index 4cd2177a33..43c66cc40f 100644
--- a/src/testdir/test_vim9_script.vim
+++ b/src/testdir/test_vim9_script.vim
@@ -253,31 +253,47 @@ enddef
def Test_block_local_vars()
var lines =<< trim END
vim9script
+ v:testing = 1
if true
- var text = 'hello'
- def SayHello(): string
+ var text = ['hello']
+ def SayHello(): list<string>
return text
enddef
def SetText(v: string)
- text = v
+ text = [v]
enddef
endif
if true
- var text = 'again'
- def SayAgain(): string
+ var text = ['again']
+ def SayAgain(): list<string>
return text
enddef
endif
+
+ # test that the "text" variables are not cleaned up
+ test_garbagecollect_now()
+
defcompile
- assert_equal('hello', SayHello())
- assert_equal('again', SayAgain())
+ assert_equal(['hello'], SayHello())
+ assert_equal(['again'], SayAgain())
SetText('foobar')
- assert_equal('foobar', SayHello())
+ assert_equal(['foobar'], SayHello())
+
+ call writefile(['ok'], 'Xdidit')
+ qall!
END
- CheckScriptSuccess(lines)
+
+ # need to execute this with a separate Vim instance to avoid the current
+ # context gets garbage collected.
+ writefile(lines, 'Xscript')
+ RunVim([], [], '-S Xscript')
+ assert_equal(['ok'], readfile('Xdidit'))
+
+ delete('Xscript')
+ delete('Xdidit')
enddef
func g:NoSuchFunc()