Patch 8.2.1817
Problem:    Vim9: wrong instruction when reusing a local variable spot.
Solution:   Clear a newly allocated local variable. (closes #7080)
Files:      src/vim9compile.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.1816/src/vim9compile.c   2020-10-05 19:23:56.216436744 +0200
--- src/vim9compile.c   2020-10-09 22:03:54.534924494 +0200
***************
*** 1690,1696 ****
   * Return the variable or NULL if it failed.
   */
      static lvar_T *
! reserve_local(cctx_T *cctx, char_u *name, size_t len, int isConst, type_T 
*type)
  {
      lvar_T  *lvar;
  
--- 1690,1701 ----
   * Return the variable or NULL if it failed.
   */
      static lvar_T *
! reserve_local(
!       cctx_T  *cctx,
!       char_u  *name,
!       size_t  len,
!       int     isConst,
!       type_T  *type)
  {
      lvar_T  *lvar;
  
***************
*** 1703,1708 ****
--- 1708,1714 ----
      if (ga_grow(&cctx->ctx_locals, 1) == FAIL)
        return NULL;
      lvar = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len++;
+     CLEAR_POINTER(lvar);
  
      // Every local variable uses the next entry on the stack.  We could re-use
      // the last ones when leaving a scope, but then variables used in a 
closure
***************
*** 4438,4444 ****
      char_u    *name_start = eap->arg;
      char_u    *name_end = to_name_end(eap->arg, TRUE);
      char_u    *lambda_name;
-     lvar_T    *lvar;
      ufunc_T   *ufunc;
      int               r;
  
--- 4444,4449 ----
***************
*** 4487,4494 ****
      else
      {
        // Define a local variable for the function reference.
!       lvar = reserve_local(cctx, name_start, name_end - name_start,
                                                    TRUE, ufunc->uf_func_type);
        if (lvar == NULL)
            return NULL;
        if (generate_FUNCREF(cctx, ufunc) == FAIL)
--- 4492,4500 ----
      else
      {
        // Define a local variable for the function reference.
!       lvar_T  *lvar = reserve_local(cctx, name_start, name_end - name_start,
                                                    TRUE, ufunc->uf_func_type);
+ 
        if (lvar == NULL)
            return NULL;
        if (generate_FUNCREF(cctx, ufunc) == FAIL)
*** ../vim-8.2.1816/src/testdir/test_vim9_func.vim      2020-10-09 
10:20:50.330911445 +0200
--- src/testdir/test_vim9_func.vim      2020-10-09 22:01:35.499292410 +0200
***************
*** 2032,2036 ****
--- 2032,2054 ----
    endtry
  enddef
  
+ " Re-using spot for variable used in block
+ def Test_block_scoped_var()
+   var lines =<< trim END
+       vim9script
+       def Func()
+         var x = ['a', 'b', 'c']
+         if 1
+           var y = 'x'
+           map(x, {-> y})
+         endif
+         var z = x
+         assert_equal(['x', 'x', 'x'], z)
+       enddef
+       Func()
+   END
+   CheckScriptSuccess(lines)
+ enddef
+ 
  
  " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker
*** ../vim-8.2.1816/src/version.c       2020-10-09 10:20:50.330911445 +0200
--- src/version.c       2020-10-09 22:04:11.950878236 +0200
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     1817,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
52. You ask a plumber how much it would cost to replace the chair in front of
    your computer with a toilet.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202010092004.099K4woS3543984%40masaka.moolenaar.net.

Raspunde prin e-mail lui