Patch 8.2.2373
Problem:    Vim9: list assignment only accepts a number index.
Solution:   Accept "any" and do a runtime type check. (closes #7694)
Files:      src/vim9compile.c, src/testdir/test_vim9_assign.vim


*** ../vim-8.2.2372/src/vim9compile.c   2021-01-17 20:23:31.303042029 +0100
--- src/vim9compile.c   2021-01-17 21:44:51.572721173 +0100
***************
*** 5802,5813 ****
        if (dest_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL)
            return FAIL;
        if (dest_type == VAR_LIST
!                    && ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type
!                                                                != VAR_NUMBER)
!       {
!           emsg(_(e_number_exp));
            return FAIL;
-       }
      }
  
      // Load the dict or list.  On the stack we then have:
--- 5802,5810 ----
        if (dest_type == VAR_DICT && may_generate_2STRING(-1, cctx) == FAIL)
            return FAIL;
        if (dest_type == VAR_LIST
!               && need_type(((type_T **)stack->ga_data)[stack->ga_len - 1],
!                                &t_number, -1, 0, cctx, FALSE, FALSE) == FAIL)
            return FAIL;
      }
  
      // Load the dict or list.  On the stack we then have:
*** ../vim-8.2.2372/src/testdir/test_vim9_assign.vim    2021-01-16 
19:01:48.944919906 +0100
--- src/testdir/test_vim9_assign.vim    2021-01-17 21:50:10.487962704 +0100
***************
*** 350,356 ****
      var lines: list<string>
      lines['a'] = 'asdf'
    END
!   CheckDefFailure(lines, 'E39:', 2)
  
    lines =<< trim END
      var lines: string
--- 350,356 ----
      var lines: list<string>
      lines['a'] = 'asdf'
    END
!   CheckDefFailure(lines, 'E1012:', 2)
  
    lines =<< trim END
      var lines: string
***************
*** 561,566 ****
--- 561,575 ----
    CheckDefExecFailure(lines, 'E1147:', 2)
  enddef
  
+ def Test_assignment_list_any_index()
+    var l: list<number> = [1, 2]
+   for  [x, y, _]
+   in  [[0, 1, ''], [1, 3, '']]
+       l[x] = l[x] + y
+   endfor
+   assert_equal([2, 5], l)
+ enddef
+ 
  def Test_assignment_list_vim9script()
    var lines =<< trim END
      vim9script
***************
*** 1405,1411 ****
    CheckDefExecFailure([
      'var ll = [1]',
      'unlet ll[g:astring]',
!     ], 'E39:', 2)
    CheckDefExecFailure([
      'var dd = test_null_dict()',
      'unlet dd["a"]',
--- 1414,1420 ----
    CheckDefExecFailure([
      'var ll = [1]',
      'unlet ll[g:astring]',
!     ], 'E1012:', 2)
    CheckDefExecFailure([
      'var dd = test_null_dict()',
      'unlet dd["a"]',
*** ../vim-8.2.2372/src/version.c       2021-01-17 20:52:08.602807027 +0100
--- src/version.c       2021-01-17 21:46:13.408534375 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2373,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
174. You know what a listserv is.

 /// 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/202101172052.10HKqFJo715199%40masaka.moolenaar.net.

Raspunde prin e-mail lui