Patch 8.2.4408
Problem:    Vim9: some code not covered by tests.
Solution:   Add a few more tests.  Correct error message.  Allow unlet on dict
            with a number key.
Files:      src/vim9execute.c, src/errors.h, src/testdir/test_vim9_assign.vim


*** ../vim-8.2.4407/src/vim9execute.c   2022-02-17 13:08:22.951193277 +0000
--- src/vim9execute.c   2022-02-17 14:31:28.726689446 +0000
***************
*** 1876,1882 ****
  }
  
  /*
!  * Store a value in a blob range.
   */
      static int
  execute_storerange(isn_T *iptr, ectx_T *ectx)
--- 1876,1882 ----
  }
  
  /*
!  * Store a value in a list or blob range.
   */
      static int
  execute_storerange(isn_T *iptr, ectx_T *ectx)
***************
*** 1893,1905 ****
      // -2 second index or "none"
      // -1 destination list or blob
      tv = STACK_TV_BOT(-4);
      if (tv_dest->v_type == VAR_LIST)
      {
        long    n1;
        long    n2;
        int     error = FALSE;
  
-       SOURCING_LNUM = iptr->isn_lnum;
        n1 = (long)tv_get_number_chk(tv_idx1, &error);
        if (error)
            status = FAIL;
--- 1893,1905 ----
      // -2 second index or "none"
      // -1 destination list or blob
      tv = STACK_TV_BOT(-4);
+     SOURCING_LNUM = iptr->isn_lnum;
      if (tv_dest->v_type == VAR_LIST)
      {
        long    n1;
        long    n2;
        int     error = FALSE;
  
        n1 = (long)tv_get_number_chk(tv_idx1, &error);
        if (error)
            status = FAIL;
***************
*** 1973,1979 ****
      else
      {
        status = FAIL;
!       emsg(_(e_blob_required));
      }
  
      clear_tv(tv_idx1);
--- 1973,1979 ----
      else
      {
        status = FAIL;
!       emsg(_(e_list_or_blob_required));
      }
  
      clear_tv(tv_idx1);
***************
*** 2001,2007 ****
      if (tv_dest->v_type == VAR_DICT)
      {
        // unlet a dict item, index must be a string
!       if (tv_idx->v_type != VAR_STRING)
        {
            SOURCING_LNUM = iptr->isn_lnum;
            semsg(_(e_expected_str_but_got_str),
--- 2001,2007 ----
      if (tv_dest->v_type == VAR_DICT)
      {
        // unlet a dict item, index must be a string
!       if (tv_idx->v_type != VAR_STRING && tv_idx->v_type != VAR_NUMBER)
        {
            SOURCING_LNUM = iptr->isn_lnum;
            semsg(_(e_expected_str_but_got_str),
***************
*** 2012,2018 ****
        else
        {
            dict_T      *d = tv_dest->vval.v_dict;
!           char_u      *key = tv_idx->vval.v_string;
            dictitem_T  *di = NULL;
  
            if (d != NULL && value_check_lock(
--- 2012,2018 ----
        else
        {
            dict_T      *d = tv_dest->vval.v_dict;
!           char_u      *key;
            dictitem_T  *di = NULL;
  
            if (d != NULL && value_check_lock(
***************
*** 2021,2028 ****
            else
            {
                SOURCING_LNUM = iptr->isn_lnum;
!               if (key == NULL)
!                   key = (char_u *)"";
                if (d != NULL)
                    di = dict_find(d, key, (int)STRLEN(key));
                if (di == NULL)
--- 2021,2036 ----
            else
            {
                SOURCING_LNUM = iptr->isn_lnum;
!               if (tv_idx->v_type == VAR_STRING)
!               {
!                   key = tv_idx->vval.v_string;
!                   if (key == NULL)
!                       key = (char_u *)"";
!               }
!               else
!               {
!                   key = tv_get_string(tv_idx);
!               }
                if (d != NULL)
                    di = dict_find(d, key, (int)STRLEN(key));
                if (di == NULL)
***************
*** 3173,3179 ****
                }
                break;
  
!           // store value in blob range
            case ISN_STORERANGE:
                if (execute_storerange(iptr, ectx) == FAIL)
                    goto on_error;
--- 3181,3187 ----
                }
                break;
  
!           // store value in list or blob range
            case ISN_STORERANGE:
                if (execute_storerange(iptr, ectx) == FAIL)
                    goto on_error;
*** ../vim-8.2.4407/src/errors.h        2022-02-15 21:17:53.144747999 +0000
--- src/errors.h        2022-02-17 13:34:58.728742488 +0000
***************
*** 3010,3017 ****
        INIT(= N_("E1180: Variable arguments type must be a list: %s"));
  EXTERN char e_cannot_use_underscore_here[]
        INIT(= N_("E1181: Cannot use an underscore here"));
! EXTERN char e_blob_required[]
!       INIT(= N_("E1182: Blob required"));
  EXTERN char e_cannot_use_range_with_assignment_operator_str[]
        INIT(= N_("E1183: Cannot use a range with an assignment operator: %s"));
  #endif
--- 3010,3016 ----
        INIT(= N_("E1180: Variable arguments type must be a list: %s"));
  EXTERN char e_cannot_use_underscore_here[]
        INIT(= N_("E1181: Cannot use an underscore here"));
! // E1182 unused
  EXTERN char e_cannot_use_range_with_assignment_operator_str[]
        INIT(= N_("E1183: Cannot use a range with an assignment operator: %s"));
  #endif
*** ../vim-8.2.4407/src/testdir/test_vim9_assign.vim    2022-02-17 
13:08:22.951193277 +0000
--- src/testdir/test_vim9_assign.vim    2022-02-17 14:38:55.981891629 +0000
***************
*** 610,615 ****
--- 610,621 ----
      bl[1] = 8
    END
    v9.CheckDefExecAndScriptFailure(lines, ['E1184:', 'E979:'], 2)
+ 
+   lines =<< trim END
+     g:bl = 'not a blob'
+     g:bl[1 : 2] = 8
+   END
+   v9.CheckDefExecAndScriptFailure(lines, ['E897:', 'E689:'], 2)
  enddef
  
  def Test_init_in_for_loop()
***************
*** 1231,1236 ****
--- 1237,1243 ----
          assert_equal(0z, bl)
          assert_equal({}, d)
        enddef
+       Echo()
    END
    v9.CheckScriptSuccess(lines)
  enddef
***************
*** 2070,2078 ****
      ], 'E1081:', 2)
  
    # dict unlet
!   var dd = {a: 1, b: 2, c: 3}
    unlet dd['a']
    unlet dd.c
    assert_equal({b: 2}, dd)
  
    # list unlet
--- 2077,2086 ----
      ], 'E1081:', 2)
  
    # dict unlet
!   var dd = {a: 1, b: 2, c: 3, 4: 4}
    unlet dd['a']
    unlet dd.c
+   unlet dd[4]
    assert_equal({b: 2}, dd)
  
    # list unlet
***************
*** 2181,2186 ****
--- 2189,2199 ----
      'unlet dd[g:alist]',
      ], 'E1105:', 2)
  
+   v9.CheckDefExecFailure([
+     'g:dd = {"a": 1, 2: 2}'
+     'unlet g:dd[0z11]',
+     ], 'E1029:', 2)
+ 
    # can compile unlet before variable exists
    g:someDict = {key: 'val'}
    var k = 'key'
*** ../vim-8.2.4407/src/version.c       2022-02-17 13:08:22.955193271 +0000
--- src/version.c       2022-02-17 14:41:00.385505100 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4408,
  /**/

-- 
I'm trying to be an optimist, but I don't think it'll work.

 /// 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/20220217144302.E55301C0FE0%40moolenaar.net.

Raspunde prin e-mail lui