Mercurial > vim
comparison src/testdir/test_vim9_script.vim @ 22602:2c77ec32deeb v8.2.1849
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Commit: https://github.com/vim/vim/commit/ed234f24f3a6d697ba9b786d0bc74d4682bfdf47
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Oct 15 20:42:20 2020 +0200
patch 8.2.1849: Vim9: garbage collection frees block-local variables
Problem: Vim9: garbage collection frees block-local variables.
Solution: Mark all script variables as used.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 15 Oct 2020 20:45:05 +0200 |
parents | 107eae953b87 |
children | b08f435d5b86 |
comparison
equal
deleted
inserted
replaced
22601:e4ba57ce600b | 22602:2c77ec32deeb |
---|---|
251 enddef | 251 enddef |
252 | 252 |
253 def Test_block_local_vars() | 253 def Test_block_local_vars() |
254 var lines =<< trim END | 254 var lines =<< trim END |
255 vim9script | 255 vim9script |
256 v:testing = 1 | |
256 if true | 257 if true |
257 var text = 'hello' | 258 var text = ['hello'] |
258 def SayHello(): string | 259 def SayHello(): list<string> |
259 return text | 260 return text |
260 enddef | 261 enddef |
261 def SetText(v: string) | 262 def SetText(v: string) |
262 text = v | 263 text = [v] |
263 enddef | 264 enddef |
264 endif | 265 endif |
265 | 266 |
266 if true | 267 if true |
267 var text = 'again' | 268 var text = ['again'] |
268 def SayAgain(): string | 269 def SayAgain(): list<string> |
269 return text | 270 return text |
270 enddef | 271 enddef |
271 endif | 272 endif |
273 | |
274 # test that the "text" variables are not cleaned up | |
275 test_garbagecollect_now() | |
276 | |
272 defcompile | 277 defcompile |
273 | 278 |
274 assert_equal('hello', SayHello()) | 279 assert_equal(['hello'], SayHello()) |
275 assert_equal('again', SayAgain()) | 280 assert_equal(['again'], SayAgain()) |
276 | 281 |
277 SetText('foobar') | 282 SetText('foobar') |
278 assert_equal('foobar', SayHello()) | 283 assert_equal(['foobar'], SayHello()) |
279 END | 284 |
280 CheckScriptSuccess(lines) | 285 call writefile(['ok'], 'Xdidit') |
286 qall! | |
287 END | |
288 | |
289 # need to execute this with a separate Vim instance to avoid the current | |
290 # context gets garbage collected. | |
291 writefile(lines, 'Xscript') | |
292 RunVim([], [], '-S Xscript') | |
293 assert_equal(['ok'], readfile('Xdidit')) | |
294 | |
295 delete('Xscript') | |
296 delete('Xdidit') | |
281 enddef | 297 enddef |
282 | 298 |
283 func g:NoSuchFunc() | 299 func g:NoSuchFunc() |
284 echo 'none' | 300 echo 'none' |
285 endfunc | 301 endfunc |