0
0
mirror of https://github.com/vim/vim.git synced 2025-10-04 05:25:06 -04:00

patch 8.2.1870: Vim9: no need to keep all script variables

Problem:    Vim9: no need to keep all script variables.
Solution:   Only keep script variables when a function was defined that could
            use them.  Fix freeing static string on exit.
This commit is contained in:
Bram Moolenaar
2020-10-20 14:25:07 +02:00
parent 955347cc7e
commit 39ca4127a0
7 changed files with 76 additions and 19 deletions

View File

@@ -296,6 +296,25 @@ def Test_block_local_vars()
delete('Xdidit')
enddef
def Test_block_local_vars_with_func()
var lines =<< trim END
vim9script
if true
var foo = 'foo'
if true
var bar = 'bar'
def Func(): list<string>
return [foo, bar]
enddef
endif
endif
# function is compiled here, after blocks have finished, can still access
# "foo" and "bar"
assert_equal(['foo', 'bar'], Func())
END
CheckScriptSuccess(lines)
enddef
func g:NoSuchFunc()
echo 'none'
endfunc