Patch 8.2.2000
Problem:    Vim9: dict.key assignment not implemented yet.
Solution:   Implement dict.key assignment. (closes #7312)
Files:      src/vim9compile.c, src/testdir/test_vim9_assign.vim


*** ../vim-8.2.1999/src/vim9compile.c   2020-11-16 20:08:32.395713947 +0100
--- src/vim9compile.c   2020-11-16 22:07:32.854221102 +0100
***************
*** 5384,5397 ****
        member_type = type;
        if (var_end > var_start + varlen)
        {
!           // Something follows after the variable: "var[idx]".
            if (is_decl)
            {
                emsg(_(e_cannot_use_index_when_declaring_variable));
                goto theend;
            }
  
!           if (var_start[varlen] == '[')
            {
                has_index = TRUE;
                if (type->tt_member == NULL)
--- 5384,5397 ----
        member_type = type;
        if (var_end > var_start + varlen)
        {
!           // Something follows after the variable: "var[idx]" or "var.key".
            if (is_decl)
            {
                emsg(_(e_cannot_use_index_when_declaring_variable));
                goto theend;
            }
  
!           if (var_start[varlen] == '[' || var_start[varlen] == '.')
            {
                has_index = TRUE;
                if (type->tt_member == NULL)
***************
*** 5635,5655 ****
        {
            int r;
  
!           // Compile the "idx" in "var[idx]".
            if (new_local)
                --cctx->ctx_locals.ga_len;
!           p = skipwhite(var_start + varlen + 1);
!           r = compile_expr0(&p, cctx);
            if (new_local)
                ++cctx->ctx_locals.ga_len;
            if (r == FAIL)
                goto theend;
!           if (*skipwhite(p) != ']')
!           {
!               // this should not happen
!               emsg(_(e_missbrac));
!               goto theend;
!           }
            if (type == &t_any)
            {
                type_T      *idx_type = ((type_T **)stack->ga_data)[
--- 5635,5667 ----
        {
            int r;
  
!           // Compile the "idx" in "var[idx]" or "key" in "var.key".
            if (new_local)
                --cctx->ctx_locals.ga_len;
!           p = var_start + varlen;
!           if (*p == '[')
!           {
!               p = skipwhite(p + 1);
!               r = compile_expr0(&p, cctx);
!               if (r == OK && *skipwhite(p) != ']')
!               {
!                   // this should not happen
!                   emsg(_(e_missbrac));
!                   r = FAIL;
!               }
!           }
!           else // if (*p == '.')
!           {
!               char_u *key_end = to_name_end(p + 1, TRUE);
!               char_u *key = vim_strnsave(p + 1, key_end - p - 1);
! 
!               r = generate_PUSHS(cctx, key);
!           }
            if (new_local)
                ++cctx->ctx_locals.ga_len;
            if (r == FAIL)
                goto theend;
! 
            if (type == &t_any)
            {
                type_T      *idx_type = ((type_T **)stack->ga_data)[
*** ../vim-8.2.1999/src/testdir/test_vim9_assign.vim    2020-11-04 
11:36:31.412190527 +0100
--- src/testdir/test_vim9_assign.vim    2020-11-16 22:06:25.050409798 +0100
***************
*** 408,413 ****
--- 408,422 ----
  
    # overwrite
    dict3['key'] = 'another'
+   assert_equal(dict3, #{key: 'another'})
+   dict3.key = 'yet another'
+   assert_equal(dict3, #{key: 'yet another'})
+ 
+   var lines =<< trim END
+     var dd = #{one: 1}
+     dd.one) = 2
+   END
+   CheckDefFailure(lines, 'E15:', 2)
  
    # empty key can be used
    var dd = {}
***************
*** 418,424 ****
    var somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
  
    # assignment to script-local dict
!   var lines =<< trim END
      vim9script
      var test: dict<any> = {}
      def FillDict(): dict<any>
--- 427,433 ----
    var somedict = rand() > 0 ? #{a: 1, b: 2} : #{a: 'a', b: 'b'}
  
    # assignment to script-local dict
!   lines =<< trim END
      vim9script
      var test: dict<any> = {}
      def FillDict(): dict<any>
*** ../vim-8.2.1999/src/version.c       2020-11-16 21:10:30.368663593 +0100
--- src/version.c       2020-11-16 22:07:52.630166262 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2000,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
258. When you want to see your girlfriend, you surf to her homepage.

 /// 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/202011162112.0AGLCS9t1275983%40masaka.moolenaar.net.

Raspunde prin e-mail lui