Mercurial > vim
diff src/testdir/test_vim9_script.vim @ 28698:096a5f9a03a8 v8.2.4873
patch 8.2.4873: Vim9: using "else" differs from using "endif/if !cond"
Commit: https://github.com/vim/vim/commit/505ed0c38f73b5c2d1695b4d51518b690d72eb3b
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu May 5 17:02:46 2022 +0100
patch 8.2.4873: Vim9: using "else" differs from using "endif/if !cond"
Problem: Vim9: using "else" differs from using "endif/if !cond".
Solution: Leave the block and enter another one. (closes https://github.com/vim/vim/issues/10320)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 05 May 2022 18:15:02 +0200 |
parents | 7f12fe85ed8b |
children | 62cef8d5dd2b |
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -1640,6 +1640,50 @@ def Test_if_elseif_else_fails() v9.CheckDefAndScriptFailure(lines, ['E1143:', 'E15:'], 4) enddef +def Test_if_else_func_using_var() + var lines =<< trim END + vim9script + + const debug = true + if debug + var mode_chars = 'something' + def Bits2Ascii() + var x = mode_chars + g:where = 'in true' + enddef + else + def Bits2Ascii() + g:where = 'in false' + enddef + endif + + Bits2Ascii() + END + v9.CheckScriptSuccess(lines) + assert_equal('in true', g:where) + unlet g:where + + lines =<< trim END + vim9script + + const debug = false + if debug + var mode_chars = 'something' + def Bits2Ascii() + g:where = 'in true' + enddef + else + def Bits2Ascii() + var x = mode_chars + g:where = 'in false' + enddef + endif + + Bits2Ascii() + END + v9.CheckScriptFailure(lines, 'E1001: Variable not found: mode_chars') +enddef + let g:bool_true = v:true let g:bool_false = v:false