Patch 8.2.2323
Problem:    Vim9: error when inferring type from empty dict/list.
Solution:   When the member is t_unknown use t_any. (closes #7009)
Files:      src/vim9compile.c, src/testdir/test_vim9_expr.vim


*** ../vim-8.2.2322/src/vim9compile.c   2021-01-10 14:02:24.658205157 +0100
--- src/vim9compile.c   2021-01-10 19:20:13.717658096 +0100
***************
*** 1899,1905 ****
      }
      // change dict type to dict member type
      if (type->tt_type == VAR_DICT)
!       ((type_T **)stack->ga_data)[stack->ga_len - 1] = type->tt_member;
  
      return OK;
  }
--- 1899,1908 ----
      }
      // change dict type to dict member type
      if (type->tt_type == VAR_DICT)
!     {
!       ((type_T **)stack->ga_data)[stack->ga_len - 1] =
!                     type->tt_member == &t_unknown ? &t_any : type->tt_member;
!     }
  
      return OK;
  }
***************
*** 3793,3799 ****
--- 3796,3807 ----
                    return FAIL;
                }
                if ((*typep)->tt_type == VAR_DICT)
+               {
                    *typep = (*typep)->tt_member;
+                   if (*typep == &t_unknown)
+                       // empty dict was used
+                       *typep = &t_any;
+               }
                else
                {
                    if (need_type(*typep, &t_dict_any, -2, cctx,
***************
*** 3831,3837 ****
--- 3839,3850 ----
                else
                {
                    if ((*typep)->tt_type == VAR_LIST)
+                   {
                        *typep = (*typep)->tt_member;
+                       if (*typep == &t_unknown)
+                           // empty list was used
+                           *typep = &t_any;
+                   }
                    if (generate_instr_drop(cctx,
                             vtype == VAR_LIST ?  ISN_LISTINDEX : ISN_ANYINDEX,
                                                                    1) == FAIL)
*** ../vim-8.2.2322/src/testdir/test_vim9_expr.vim      2021-01-09 
16:21:33.996353408 +0100
--- src/testdir/test_vim9_expr.vim      2021-01-10 19:19:00.189940642 +0100
***************
*** 2929,2934 ****
--- 2929,2944 ----
    lines = ['var l = [0, 1, 2]', 'echo l[g:astring : g:theone]']
    CheckDefExecFailure(lines, 'E1012:')
    CheckScriptFailure(['vim9script'] + lines, 'E1030:', 3)
+ 
+   lines =<< trim END
+       vim9script
+       var ld = []
+       def Func()
+         eval ld[0].key
+       enddef
+       defcompile
+   END
+   CheckScriptSuccess(lines)
  enddef
  
  def Test_expr7_dict_subscript()
***************
*** 2937,2942 ****
--- 2947,2961 ----
        var l = [{lnum: 2}, {lnum: 1}]
        var res = l[0].lnum > l[1].lnum
        assert_true(res)
+ 
+       var dd = {}
+       def Func1()
+         eval dd.key1.key2
+       enddef
+       def Func2()
+         eval dd['key1'].key2
+       enddef
+       defcompile
    END
    CheckScriptSuccess(lines)
  enddef
*** ../vim-8.2.2322/src/version.c       2021-01-10 18:33:08.011683523 +0100
--- src/version.c       2021-01-10 19:07:35.829160050 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2323,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
121. You ask for e-mail adresses instead of telephone numbers.

 /// 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/202101101823.10AINswU406072%40masaka.moolenaar.net.

Raspunde prin e-mail lui