Patch 8.2.4873
Problem:    Vim9: using "else" differs from using "endif/if !cond".
Solution:   Leave the block and enter another one. (closes #10320)
Files:      src/ex_eval.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.4872/src/ex_eval.c       2022-05-05 16:08:51.256038275 +0100
--- src/ex_eval.c       2022-05-05 16:48:14.566656114 +0100
***************
*** 1124,1129 ****
--- 1124,1134 ----
        skip = TRUE;
      }
  
+     // Variables declared in the previous block can no longer be
+     // used.  Needs to be done before setting "cs_flags".
+     leave_block(cstack);
+     enter_block(cstack);
+ 
      // if skipping or the ":if" was TRUE, reset ACTIVE, otherwise set it
      if (skip || cstack->cs_flags[cstack->cs_idx] & CSF_TRUE)
      {
*** ../vim-8.2.4872/src/testdir/test_vim9_script.vim    2022-05-05 
15:19:59.615770189 +0100
--- src/testdir/test_vim9_script.vim    2022-05-05 17:00:10.198170686 +0100
***************
*** 1640,1645 ****
--- 1640,1689 ----
    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
  
*** ../vim-8.2.4872/src/version.c       2022-05-05 16:08:51.260038271 +0100
--- src/version.c       2022-05-05 16:35:18.582988920 +0100
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4873,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
102. When filling out your driver's license application, you give
     your IP address.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220505160317.2B0CE1C0D3D%40moolenaar.net.

Raspunde prin e-mail lui