diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-10-10 19:07:09 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-10-10 19:07:09 +0200 |
commit | fcdc5d83fbfd7ddce634769ea902e58c87f27f20 (patch) | |
tree | eefebdaddad609fcd533c83744099629bd8d6112 /src/testdir/test_vim9_script.vim | |
parent | 28f224b2c1bd2fcdee7b4fe2c64826e1cff08f39 (diff) | |
download | vim-git-fcdc5d83fbfd7ddce634769ea902e58c87f27f20.tar.gz |
patch 8.2.1824: Vim9: variables at the script level escape their scopev8.2.1824
Problem: Vim9: variables at the script level escape their scope.
Solution: When leaving a scope remove variables declared in it.
Diffstat (limited to 'src/testdir/test_vim9_script.vim')
-rw-r--r-- | src/testdir/test_vim9_script.vim | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 02bc56b2f..466b2d078 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -2685,6 +2685,56 @@ def Run_Test_define_func_at_command_line() delete('Xdidcmd') enddef +def Test_script_var_scope() + var lines =<< trim END + vim9script + if true + if true + var one = 'one' + echo one + endif + echo one + endif + END + CheckScriptFailure(lines, 'E121:', 7) + + lines =<< trim END + vim9script + if true + if false + var one = 'one' + echo one + else + var one = 'one' + echo one + endif + echo one + endif + END + CheckScriptFailure(lines, 'E121:', 10) + + lines =<< trim END + vim9script + while true + var one = 'one' + echo one + break + endwhile + echo one + END + CheckScriptFailure(lines, 'E121:', 7) + + lines =<< trim END + vim9script + for i in range(1) + var one = 'one' + echo one + endfor + echo one + END + CheckScriptFailure(lines, 'E121:', 6) +enddef + " Keep this last, it messes up highlighting. def Test_substitute_cmd() new |