Patch 8.2.0536
Problem:    Vim9: some compilation code not tested.
Solution:   Add more test cases.
Files:      src/evalvars.c, src/proto/evalvars.pro, src/vim9compile.c,
            src/testdir/test_vim9_expr.vim


*** ../vim-8.2.0535/src/evalvars.c      2020-04-05 21:38:11.637962358 +0200
--- src/evalvars.c      2020-04-09 19:28:46.228692358 +0200
***************
*** 1915,1929 ****
  
  /*
   * Returns the index of a v:variable.  Negative if not found.
   */
      int
! find_vim_var(char_u *name)
  {
!     dictitem_T *di = find_var_in_ht(&vimvarht, 0, name, TRUE);
!     struct vimvar *vv;
  
      if (di == NULL)
        return -1;
      vv = (struct vimvar *)((char *)di - offsetof(vimvar_T, vv_di));
      return (int)(vv - vimvars);
  }
--- 1915,1931 ----
  
  /*
   * Returns the index of a v:variable.  Negative if not found.
+  * Returns DI_ flags in "di_flags".
   */
      int
! find_vim_var(char_u *name, int *di_flags)
  {
!     dictitem_T            *di = find_var_in_ht(&vimvarht, 0, name, TRUE);
!     struct vimvar   *vv;
  
      if (di == NULL)
        return -1;
+     *di_flags = di->di_flags;
      vv = (struct vimvar *)((char *)di - offsetof(vimvar_T, vv_di));
      return (int)(vv - vimvars);
  }
*** ../vim-8.2.0535/src/proto/evalvars.pro      2020-04-05 18:56:02.233436590 
+0200
--- src/proto/evalvars.pro      2020-04-09 19:28:51.416674629 +0200
***************
*** 28,34 ****
  dict_T *get_globvar_dict(void);
  hashtab_T *get_globvar_ht(void);
  dict_T *get_vimvar_dict(void);
! int find_vim_var(char_u *name);
  void set_vim_var_type(int idx, vartype_T type);
  void set_vim_var_nr(int idx, varnumber_T val);
  char *get_vim_var_name(int idx);
--- 28,34 ----
  dict_T *get_globvar_dict(void);
  hashtab_T *get_globvar_ht(void);
  dict_T *get_vimvar_dict(void);
! int find_vim_var(char_u *name, int *di_flags);
  void set_vim_var_type(int idx, vartype_T type);
  void set_vim_var_nr(int idx, varnumber_T val);
  char *get_vim_var_name(int idx);
*** ../vim-8.2.0535/src/vim9compile.c   2020-04-07 22:44:56.778289142 +0200
--- src/vim9compile.c   2020-04-09 19:33:26.531732690 +0200
***************
*** 403,409 ****
        return &t_list_string;
      if (tv->v_type == VAR_DICT)  // e.g. for v:completed_item
        return &t_dict_any;
!     return &t_any;
  }
  
  /////////////////////////////////////////////////////////////////////
--- 403,409 ----
        return &t_list_string;
      if (tv->v_type == VAR_DICT)  // e.g. for v:completed_item
        return &t_dict_any;
!     return &t_any;  // not used
  }
  
  /////////////////////////////////////////////////////////////////////
***************
*** 974,980 ****
  }
  
  /*
!  * Generate an ISN_LOADV instruction.
   */
      static int
  generate_LOADV(
--- 974,980 ----
  }
  
  /*
!  * Generate an ISN_LOADV instruction for v:var.
   */
      static int
  generate_LOADV(
***************
*** 982,989 ****
        char_u      *name,
        int         error)
  {
!     // load v:var
!     int vidx = find_vim_var(name);
  
      RETURN_OK_IF_SKIP(cctx);
      if (vidx < 0)
--- 982,990 ----
        char_u      *name,
        int         error)
  {
!     int           di_flags;
!     int           vidx = find_vim_var(name, &di_flags);
!     type_T  *type;
  
      RETURN_OK_IF_SKIP(cctx);
      if (vidx < 0)
***************
*** 992,1000 ****
            semsg(_(e_var_notfound), name);
        return FAIL;
      }
  
!     // TODO: get actual type
!     return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, &t_any);
  }
  
  /*
--- 993,1001 ----
            semsg(_(e_var_notfound), name);
        return FAIL;
      }
+     type = typval2type(get_vim_var_tv(vidx));
  
!     return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, type);
  }
  
  /*
***************
*** 3907,3920 ****
        }
        else if (STRNCMP(arg, "v:", 2) == 0)
        {
!           typval_T *vtv;
  
!           vimvaridx = find_vim_var(name + 2);
            if (vimvaridx < 0)
            {
                semsg(_(e_var_notfound), arg);
                goto theend;
            }
            dest = dest_vimvar;
            vtv = get_vim_var_tv(vimvaridx);
            type = typval2type(vtv);
--- 3908,3925 ----
        }
        else if (STRNCMP(arg, "v:", 2) == 0)
        {
!           typval_T    *vtv;
!           int         di_flags;
  
!           vimvaridx = find_vim_var(name + 2, &di_flags);
            if (vimvaridx < 0)
            {
                semsg(_(e_var_notfound), arg);
                goto theend;
            }
+           // We use the current value of "sandbox" here, is that OK?
+           if (var_check_ro(di_flags, name, FALSE))
+               goto theend;
            dest = dest_vimvar;
            vtv = get_vim_var_tv(vimvaridx);
            type = typval2type(vtv);
*** ../vim-8.2.0535/src/testdir/test_vim9_expr.vim      2020-04-05 
17:07:59.418556237 +0200
--- src/testdir/test_vim9_expr.vim      2020-04-09 19:31:50.436062053 +0200
***************
*** 711,722 ****
--- 711,738 ----
    call CheckDefFailure("let x = 'abc", 'E115:')
  enddef
  
+ def Test_expr7_vimvar()
+   let old: list<string> = v:oldfiles
+   let compl: dict<any> = v:completed_item
+ 
+   call CheckDefFailure("let old: list<number> = v:oldfiles", 'E1013: type 
mismatch, expected list<number> but got list<string>')
+   call CheckDefFailure("let old: dict<number> = v:completed_item", 'E1013: 
type mismatch, expected dict<number> but got dict<any>')
+ enddef
+ 
  def Test_expr7_special()
    " special constant
    assert_equal(g:special_true, true)
    assert_equal(g:special_false, false)
+   assert_equal(g:special_true, v:true)
+   assert_equal(g:special_false, v:false)
    assert_equal(g:special_null, v:null)
    assert_equal(g:special_none, v:none)
+ 
+   call CheckDefFailure('v:true = true', 'E46:')
+   call CheckDefFailure('v:true = false', 'E46:')
+   call CheckDefFailure('v:false = true', 'E46:')
+   call CheckDefFailure('v:null = 11', 'E46:')
+   call CheckDefFailure('v:none = 22', 'E46:')
  enddef
  
  def Test_expr7_list()
***************
*** 962,968 ****
    call CheckDefFailure("CallMe2('yes' , 'no')", 'E1068:')
  
    call CheckDefFailure("v:nosuch += 3", 'E1001:')
!   call CheckDefFailure("let v:version = 3", 'E1064:')
    call CheckDefFailure("let asdf = v:nosuch", 'E1001:')
  
    call CheckDefFailure("echo len('asdf'", 'E110:')
--- 978,984 ----
    call CheckDefFailure("CallMe2('yes' , 'no')", 'E1068:')
  
    call CheckDefFailure("v:nosuch += 3", 'E1001:')
!   call CheckDefFailure("let v:statusmsg = ''", 'E1064:')
    call CheckDefFailure("let asdf = v:nosuch", 'E1001:')
  
    call CheckDefFailure("echo len('asdf'", 'E110:')
*** ../vim-8.2.0535/src/version.c       2020-04-09 18:42:08.362066431 +0200
--- src/version.c       2020-04-09 18:57:32.934897155 +0200
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     536,
  /**/

-- 
Living on Earth includes an annual free trip around the Sun.

 /// 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/202004091735.039HZ9js031032%40masaka.moolenaar.net.

Raspunde prin e-mail lui