Patch 8.2.2159
Problem:    Vim9: when declaring a list it is not allocated yet, causing a
            following extend() to fail.
Solution:   When fetching a variable value for a list or dict that is null
            allocate the list or dict, so it can be used. (closes #7491)
Files:      src/vim9execute.c, src/testdir/test_vim9_assign.vim


*** ../vim-8.2.2158/src/vim9execute.c   2020-12-12 20:42:16.123207537 +0100
--- src/vim9execute.c   2020-12-18 17:22:39.654455314 +0100
***************
*** 791,796 ****
--- 791,816 ----
      restore_funccal();
  }
  
+ /*
+  * When the value of "sv" is a null list of dict, allocate it.
+  */
+     static void
+ allocate_if_null(typval_T *tv)
+ {
+     switch (tv->v_type)
+     {
+       case VAR_LIST:
+           if (tv->vval.v_list == NULL)
+               rettv_list_alloc(tv);
+           break;
+       case VAR_DICT:
+           if (tv->vval.v_dict == NULL)
+               rettv_dict_alloc(tv);
+           break;
+       default:
+           break;
+     }
+ }
  
  /*
   * Execute a function by "name".
***************
*** 1289,1294 ****
--- 1309,1315 ----
  
                    sv = ((svar_T *)si->sn_var_vals.ga_data)
                                             + iptr->isn_arg.script.script_idx;
+                   allocate_if_null(sv->sv_tv);
                    if (GA_GROW(&ectx.ec_stack, 1) == FAIL)
                        goto failed;
                    copy_tv(sv->sv_tv, STACK_TV_BOT(0));
*** ../vim-8.2.2158/src/testdir/test_vim9_assign.vim    2020-12-18 
15:37:57.248171925 +0100
--- src/testdir/test_vim9_assign.vim    2020-12-18 17:17:04.923439023 +0100
***************
*** 391,396 ****
--- 391,406 ----
        assert_equal(['a', 'b'], list)
    END
    CheckScriptSuccess(lines)
+   lines =<< trim END
+       vim9script
+       var list: list<string>
+       def Func()
+         extend(list, ['x', 'b'])
+       enddef
+       Func()
+       assert_equal(['x', 'b'], list)
+   END
+   CheckScriptSuccess(lines)
  
    lines =<< trim END
        vim9script
***************
*** 584,591 ****
        return test
      enddef
      FillDict()
    END
!   CheckScriptFailure(lines, 'E1103:')
  
    # assignment to global dict
    lines =<< trim END
--- 594,602 ----
        return test
      enddef
      FillDict()
+     assert_equal({a: 43}, test)
    END
!   CheckScriptSuccess(lines)
  
    # assignment to global dict
    lines =<< trim END
*** ../vim-8.2.2158/src/version.c       2020-12-18 16:29:21.716008176 +0100
--- src/version.c       2020-12-18 17:05:52.817555014 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2159,
  /**/

-- 
BLACK KNIGHT: The Black Knight always triumphs. Have at you!
   ARTHUR takes his last leg off.  The BLACK KNIGHT's body lands upright.
BLACK KNIGHT: All right, we'll call it a draw.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- b...@moolenaar.net -- 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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202012181623.0BIGNgSv1305092%40masaka.moolenaar.net.

Raspunde prin e-mail lui