Patch 8.2.3322
Problem:    Vim9: checking type of dict does not check member type.
Solution:   When getting the type of a typval use dv_type and lv_type.
            (closes #8732)
Files:      src/vim9type.c, src/testdir/test_vim9_builtin.vim


*** ../vim-8.2.3321/src/vim9type.c      2021-08-09 19:59:01.446811234 +0200
--- src/vim9type.c      2021-08-09 22:13:05.501879011 +0200
***************
*** 274,283 ****
        list_T      *l = tv->vval.v_list;
        listitem_T  *li;
  
!       if (l == NULL || l->lv_first == NULL)
            return &t_list_empty;
        if (!do_member)
            return &t_list_any;
        if (l->lv_first == &range_list_item)
            return &t_list_number;
        if (l->lv_copyID == copyID)
--- 274,285 ----
        list_T      *l = tv->vval.v_list;
        listitem_T  *li;
  
!       if (l == NULL || (l->lv_first == NULL && l->lv_type == NULL))
            return &t_list_empty;
        if (!do_member)
            return &t_list_any;
+       if (l->lv_type != NULL)
+           return l->lv_type;
        if (l->lv_first == &range_list_item)
            return &t_list_number;
        if (l->lv_copyID == copyID)
***************
*** 299,308 ****
        typval_T        *value;
        dict_T          *d = tv->vval.v_dict;
  
!       if (d == NULL || d->dv_hashtab.ht_used == 0)
            return &t_dict_empty;
        if (!do_member)
            return &t_dict_any;
        if (d->dv_copyID == copyID)
            // avoid recursion
            return &t_dict_any;
--- 301,312 ----
        typval_T        *value;
        dict_T          *d = tv->vval.v_dict;
  
!       if (d == NULL || (d->dv_hashtab.ht_used == 0 && d->dv_type == NULL))
            return &t_dict_empty;
        if (!do_member)
            return &t_dict_any;
+       if (d->dv_type != NULL)
+           return d->dv_type;
        if (d->dv_copyID == copyID)
            // avoid recursion
            return &t_dict_any;
*** ../vim-8.2.3321/src/testdir/test_vim9_builtin.vim   2021-08-08 
14:41:48.723930691 +0200
--- src/testdir/test_vim9_builtin.vim   2021-08-09 22:13:28.157821788 +0200
***************
*** 922,927 ****
--- 922,933 ----
    END
    CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got 
string', 0)
    CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
+ 
+   lines =<< trim END
+        var d: dict<bool>
+        extend(d, {b: 0})
+   END
+   CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected 
dict<bool> but got dict<number>', 2)
  enddef
  
  func g:ExtendList(l)
***************
*** 947,952 ****
--- 953,964 ----
    END
    CheckDefExecFailure(lines, 'E1012: Type mismatch; expected number but got 
string', 0)
    CheckScriptFailure(['vim9script'] + lines, 'E1012:', 1)
+ 
+   lines =<< trim END
+        var l: list<bool>
+        extend(l, [0])
+   END
+   CheckDefAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected 
list<bool> but got list<number>', 2)
  enddef
  
  def Test_extend_return_type()
*** ../vim-8.2.3321/src/version.c       2021-08-09 21:04:20.948157277 +0200
--- src/version.c       2021-08-09 22:03:35.107316137 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3322,
  /**/

-- 
MARTHA'S WAY: Don't throw out all that leftover wine. Freeze into ice cubes
              for future use in casseroles and sauces.
MY WAY:       What leftover wine?

 /// 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/202108092023.179KN4S92474112%40masaka.moolenaar.net.

Raspunde prin e-mail lui