diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-10-15 12:46:44 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-10-15 12:46:44 +0200 |
commit | fbbcd00367e1a4fafd047d42ffce0e5dce88925c (patch) | |
tree | 93f997f2b6fad6457ff728399b8be9da35ad1ead /src/testdir/test_vim9_script.vim | |
parent | 8d739de43b84ef7817b3b5b826d1cbfe7572a62a (diff) |
patch 8.2.1846: Vim9: block variables are not found in compiled functionv8.2.1846
Problem: Vim9: variables declared in a local block are not found in
when a function is compiled.
Solution: Look for script variables in sn_all_vars.
Diffstat (limited to 'src/testdir/test_vim9_script.vim')
-rw-r--r-- | src/testdir/test_vim9_script.vim | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 1edc773cc1..4cd2177a33 100644 --- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -250,6 +250,36 @@ def Test_block_failure() CheckDefFailure(['{', 'echo 1'], 'E1026:') enddef +def Test_block_local_vars() + var lines =<< trim END + vim9script + if true + var text = 'hello' + def SayHello(): string + return text + enddef + def SetText(v: string) + text = v + enddef + endif + + if true + var text = 'again' + def SayAgain(): string + return text + enddef + endif + defcompile + + assert_equal('hello', SayHello()) + assert_equal('again', SayAgain()) + + SetText('foobar') + assert_equal('foobar', SayHello()) + END + CheckScriptSuccess(lines) +enddef + func g:NoSuchFunc() echo 'none' endfunc @@ -1265,15 +1295,16 @@ def Test_import_absolute() assert_equal(9876, g:imported_abs) assert_equal(8888, g:imported_after) - assert_match('<SNR>\d\+_UseExported.*' .. - 'g:imported_abs = exported.*' .. - '0 LOADSCRIPT exported from .*Xexport_abs.vim.*' .. - '1 STOREG g:imported_abs.*' .. - 'exported = 8888.*' .. - '3 STORESCRIPT exported in .*Xexport_abs.vim.*' .. - 'g:imported_after = exported.*' .. - '4 LOADSCRIPT exported from .*Xexport_abs.vim.*' .. - '5 STOREG g:imported_after.*', + assert_match('<SNR>\d\+_UseExported\_s*' .. + 'g:imported_abs = exported\_s*' .. + '0 LOADSCRIPT exported-2 from .*Xexport_abs.vim\_s*' .. + '1 STOREG g:imported_abs\_s*' .. + 'exported = 8888\_s*' .. + '2 PUSHNR 8888\_s*' .. + '3 STORESCRIPT exported-2 in .*Xexport_abs.vim\_s*' .. + 'g:imported_after = exported\_s*' .. + '4 LOADSCRIPT exported-2 from .*Xexport_abs.vim\_s*' .. + '5 STOREG g:imported_after', g:import_disassembled) Undo_export_script_lines() |