Patch 8.2.4310
Problem:    Vim9: constant list and dict get a declaration type other than
            "any".
Solution:   A constant list and dict have a declared member type "any".
            (closes #9701)
Files:      src/vim9instr.c, src/vim9type.c, src/proto/vim9type.pro,
            src/testdir/test_vim9_builtin.vim


*** ../vim-8.2.4309/src/vim9instr.c     2022-02-01 12:11:53.443042004 +0000
--- src/vim9instr.c     2022-02-06 15:47:04.945498363 +0000
***************
*** 1067,1073 ****
  {
      isn_T     *isn;
      type_T    *member_type;
-     type_T    *decl_member_type;
      type_T    *type;
      type_T    *decl_type;
  
--- 1067,1072 ----
***************
*** 1078,1087 ****
  
      // Get the member type and the declared member type from all the items on
      // the stack.
!     member_type = get_member_type_from_stack(count, 1,
!                                                     &decl_member_type, cctx);
      type = get_list_type(member_type, cctx->ctx_type_list);
!     decl_type = get_list_type(decl_member_type, cctx->ctx_type_list);
  
      // drop the value types
      cctx->ctx_type_stack.ga_len -= count;
--- 1077,1085 ----
  
      // Get the member type and the declared member type from all the items on
      // the stack.
!     member_type = get_member_type_from_stack(count, 1, cctx);
      type = get_list_type(member_type, cctx->ctx_type_list);
!     decl_type = get_list_type(&t_any, cctx->ctx_type_list);
  
      // drop the value types
      cctx->ctx_type_stack.ga_len -= count;
***************
*** 1098,1104 ****
  {
      isn_T     *isn;
      type_T    *member_type;
-     type_T    *decl_member_type;
      type_T    *type;
      type_T    *decl_type;
  
--- 1096,1101 ----
***************
*** 1107,1116 ****
        return FAIL;
      isn->isn_arg.number = count;
  
!     member_type = get_member_type_from_stack(count, 2,
!                                                     &decl_member_type, cctx);
      type = get_dict_type(member_type, cctx->ctx_type_list);
!     decl_type = get_dict_type(decl_member_type, cctx->ctx_type_list);
  
      // drop the key and value types
      cctx->ctx_type_stack.ga_len -= 2 * count;
--- 1104,1112 ----
        return FAIL;
      isn->isn_arg.number = count;
  
!     member_type = get_member_type_from_stack(count, 2, cctx);
      type = get_dict_type(member_type, cctx->ctx_type_list);
!     decl_type = get_dict_type(&t_any, cctx->ctx_type_list);
  
      // drop the key and value types
      cctx->ctx_type_stack.ga_len -= 2 * count;
*** ../vim-8.2.4309/src/vim9type.c      2022-02-03 12:34:00.665140482 +0000
--- src/vim9type.c      2022-02-06 15:47:45.185432177 +0000
***************
*** 1359,1365 ****
  get_member_type_from_stack(
        int         count,
        int         skip,
-       type_T      **decl_type,
        cctx_T      *cctx)
  {
      garray_T  *stack = &cctx->ctx_type_stack;
--- 1359,1364 ----
***************
*** 1367,1398 ****
      garray_T    *type_gap = cctx->ctx_type_list;
      int               i;
      type_T    *result;
-     type_T    *decl_result;
      type_T    *type;
  
      // Use "unknown" for an empty list or dict.
      if (count == 0)
-     {
-       *decl_type = &t_unknown;
        return &t_unknown;
-     }
  
      // Use the first value type for the list member type, then find the common
      // type from following items.
      typep = ((type2_T *)stack->ga_data) + stack->ga_len;
      result = (typep -(count * skip) + skip - 1)->type_curr;
-     decl_result = (typep -(count * skip) + skip - 1)->type_decl;
      for (i = 1; i < count; ++i)
      {
        if (result == &t_any)
            break;  // won't get more common
        type = (typep -((count - i) * skip) + skip - 1)->type_curr;
        common_type(type, result, &result, type_gap);
-       type = (typep -((count - i) * skip) + skip - 1)->type_decl;
-       common_type(type, decl_result, &decl_result, type_gap);
      }
  
-     *decl_type = decl_result;
      return result;
  }
  
--- 1366,1389 ----
*** ../vim-8.2.4309/src/proto/vim9type.pro      2022-02-02 20:01:21.957210955 
+0000
--- src/proto/vim9type.pro      2022-02-06 15:48:04.945399740 +0000
***************
*** 27,33 ****
  void set_type_on_stack(cctx_T *cctx, type_T *type, int offset);
  type_T *get_type_on_stack(cctx_T *cctx, int offset);
  type_T *get_decl_type_on_stack(cctx_T *cctx, int offset);
! type_T *get_member_type_from_stack(int count, int skip, type_T **decl_type, 
cctx_T *cctx);
  char *vartype_name(vartype_T type);
  char *type_name(type_T *type, char **tofree);
  void f_typename(typval_T *argvars, typval_T *rettv);
--- 27,33 ----
  void set_type_on_stack(cctx_T *cctx, type_T *type, int offset);
  type_T *get_type_on_stack(cctx_T *cctx, int offset);
  type_T *get_decl_type_on_stack(cctx_T *cctx, int offset);
! type_T *get_member_type_from_stack(int count, int skip, cctx_T *cctx);
  char *vartype_name(vartype_T type);
  char *type_name(type_T *type, char **tofree);
  void f_typename(typval_T *argvars, typval_T *rettv);
*** ../vim-8.2.4309/src/testdir/test_vim9_builtin.vim   2022-02-05 
19:23:14.254442007 +0000
--- src/testdir/test_vim9_builtin.vim   2022-02-06 15:44:13.601782506 +0000
***************
*** 2237,2242 ****
--- 2237,2247 ----
        g:gl = l
        map(g:gl, (k, v) => true)
        assert_equal([true], g:gl)
+ 
+       assert_equal(['x'], [[1, 2]]->map((_, v) => 'x'))
+       assert_equal(['x'], [{a: 0}]->map((_, v) => 'x'))
+       assert_equal({a: 'x'}, {a: [1, 2]}->map((_, v) => 'x'))
+       assert_equal({a: 'x'}, {a: {b: 2}}->map((_, v) => 'x'))
    END
    v9.CheckDefAndScriptSuccess(lines)
  enddef
*** ../vim-8.2.4309/src/version.c       2022-02-06 13:54:59.236437901 +0000
--- src/version.c       2022-02-06 15:36:18.310535054 +0000
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     4310,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
12. You turn off your Wifi and get this awful empty feeling, like you just
    pulled the plug on a loved one.

 /// 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/20220206155336.B00D61C07B2%40moolenaar.net.

Raspunde prin e-mail lui