Patch 8.2.3055
Problem:    Strange error for assigning to "x.key" on non-dictionary.
Solution:   Add a specific error message. (closes #8451)
Files:      src/eval.c, src/errors.h, src/testdir/test_vim9_assign.vim,
            src/testdir/test_listdict.vim, src/testdir/test_let.vim


*** ../vim-8.2.3054/src/eval.c  2021-06-17 22:08:13.372738586 +0200
--- src/eval.c  2021-06-26 14:58:44.925506782 +0200
***************
*** 924,931 ****
      lp->ll_tv = &v->di_tv;
      var1.v_type = VAR_UNKNOWN;
      var2.v_type = VAR_UNKNOWN;
!     while (*p == '[' || (*p == '.' && lp->ll_tv->v_type == VAR_DICT))
      {
        if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
                && !(lp->ll_tv->v_type == VAR_DICT)
                && !(lp->ll_tv->v_type == VAR_BLOB
--- 924,937 ----
      lp->ll_tv = &v->di_tv;
      var1.v_type = VAR_UNKNOWN;
      var2.v_type = VAR_UNKNOWN;
!     while (*p == '[' || (*p == '.' && p[1] != '=' && p[1] != '.'))
      {
+       if (*p == '.' && lp->ll_tv->v_type != VAR_DICT)
+       {
+           if (!quiet)
+               semsg(_(e_dot_can_only_be_used_on_dictionary_str), name);
+           return NULL;
+       }
        if (!(lp->ll_tv->v_type == VAR_LIST && lp->ll_tv->vval.v_list != NULL)
                && !(lp->ll_tv->v_type == VAR_DICT)
                && !(lp->ll_tv->v_type == VAR_BLOB
*** ../vim-8.2.3054/src/errors.h        2021-06-26 13:59:26.351498193 +0200
--- src/errors.h        2021-06-26 14:12:29.010269966 +0200
***************
*** 448,450 ****
--- 448,452 ----
        INIT(= N_("E1201: Decryption failed: pre-mature end of file!"));
  EXTERN char e_no_white_space_allowed_after_str_str[]
        INIT(= N_("E1202: No white space allowed after '%s': %s"));
+ EXTERN char e_dot_can_only_be_used_on_dictionary_str[]
+       INIT(= N_("E1203: Dot can only be used on a dictionary: %s"));
*** ../vim-8.2.3054/src/testdir/test_vim9_assign.vim    2021-06-26 
13:59:26.351498193 +0200
--- src/testdir/test_vim9_assign.vim    2021-06-26 14:26:35.276734150 +0200
***************
*** 787,792 ****
--- 787,798 ----
      d.dd[0] = 0
    END
    CheckDefExecFailure(lines, 'E1148:', 2)
+ 
+   lines =<< trim END
+     var n: any
+     n.key = 5
+   END
+   CheckDefExecAndScriptFailure2(lines, 'E1148:', 'E1203: Dot can only be used 
on a dictionary: n.key = 5', 2)
  enddef
  
  def Test_assignment_local()
*** ../vim-8.2.3054/src/testdir/test_listdict.vim       2021-06-06 
14:14:35.352774336 +0200
--- src/testdir/test_listdict.vim       2021-06-26 14:19:34.725510003 +0200
***************
*** 294,299 ****
--- 294,302 ----
    let d.1 = 1
    let d._ = 2
    call assert_equal({'1': 1, '_': 2}, d)
+ 
+   let n = 0
+   call assert_fails('let n.key = 3', 'E1203: Dot can only be used on a 
dictionary: n.key = 3')
  endfunc
  
  " Function in script-local List or Dict
*** ../vim-8.2.3054/src/testdir/test_let.vim    2021-06-17 22:08:13.376738576 
+0200
--- src/testdir/test_let.vim    2021-06-26 14:52:41.786139763 +0200
***************
*** 293,299 ****
    let s = "var"
    let var = 1
    call assert_fails('let var += [1,2]', 'E734:')
!   call assert_fails('let {s}.1 = 2', 'E18:')
    call assert_fails('let a[1] = 5', 'E121:')
    let l = [[1,2]]
    call assert_fails('let l[:][0] = [5]', 'E708:')
--- 293,299 ----
    let s = "var"
    let var = 1
    call assert_fails('let var += [1,2]', 'E734:')
!   call assert_fails('let {s}.1 = 2', 'E1203:')
    call assert_fails('let a[1] = 5', 'E121:')
    let l = [[1,2]]
    call assert_fails('let l[:][0] = [5]', 'E708:')
*** ../vim-8.2.3054/src/version.c       2021-06-26 13:59:26.355498184 +0200
--- src/version.c       2021-06-26 14:14:11.478090658 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3055,
  /**/

-- 
Know this story about a nerd who fell into a river and drowned,
despite his cries of "F1! F1!"?

 /// 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/202106261301.15QD1UUQ333381%40masaka.moolenaar.net.

Raspunde prin e-mail lui