]> granicus.if.org Git - vim/commitdiff
patch 8.2.0536: Vim9: some compilation code not tested v8.2.0536
authorBram Moolenaar <Bram@vim.org>
Thu, 9 Apr 2020 17:34:43 +0000 (19:34 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 9 Apr 2020 17:34:43 +0000 (19:34 +0200)
Problem:    Vim9: some compilation code not tested.
Solution:   Add more test cases.

src/evalvars.c
src/proto/evalvars.pro
src/testdir/test_vim9_expr.vim
src/version.c
src/vim9compile.c

index 6b9c270a377199f0a996a25af310322f651d3289..8af80ec0afe92e1f1283ddd687744214415b2a59 100644 (file)
@@ -1915,15 +1915,17 @@ get_vimvar_dict(void)
 
 /*
  * Returns the index of a v:variable.  Negative if not found.
+ * Returns DI_ flags in "di_flags".
  */
     int
-find_vim_var(char_u *name)
+find_vim_var(char_u *name, int *di_flags)
 {
-    dictitem_T *di = find_var_in_ht(&vimvarht, 0, name, TRUE);
-    struct vimvar *vv;
+    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);
 }
index 4338b20f73e6c43d5dbd7bafa9bbb717eecf5033..352097d430a334726a073b19a9d3e41a481dd890 100644 (file)
@@ -28,7 +28,7 @@ char *get_var_special_name(int nr);
 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 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);
index f11fc83893502f36cd85964c81e8adc7eb47c95d..f34041b5d2caddb5cba1568ab2881af601cad3e7 100644 (file)
@@ -711,12 +711,28 @@ def Test_expr7_string()
   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,7 +978,7 @@ func Test_expr_fails()
   call CheckDefFailure("CallMe2('yes' , 'no')", 'E1068:')
 
   call CheckDefFailure("v:nosuch += 3", 'E1001:')
-  call CheckDefFailure("let v:version = 3", 'E1064:')
+  call CheckDefFailure("let v:statusmsg = ''", 'E1064:')
   call CheckDefFailure("let asdf = v:nosuch", 'E1001:')
 
   call CheckDefFailure("echo len('asdf'", 'E110:')
index 78bb33262ee4d5507f5d091558ba1fdb8b4ae111..1faac9606698e7bfd63e4bcbdf399363ec154c73 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    536,
 /**/
     535,
 /**/
index a8a7647468bd2e70d3181fa4d28a7eac8c25b55c..0bc50c3e02d7d7f8b56c1604e267a2131611cf83 100644 (file)
@@ -403,7 +403,7 @@ typval2type(typval_T *tv)
        return &t_list_string;
     if (tv->v_type == VAR_DICT)  // e.g. for v:completed_item
        return &t_dict_any;
-    return &t_any;
+    return &t_any;  // not used
 }
 
 /////////////////////////////////////////////////////////////////////
@@ -974,7 +974,7 @@ generate_LOAD(
 }
 
 /*
- * Generate an ISN_LOADV instruction.
+ * Generate an ISN_LOADV instruction for v:var.
  */
     static int
 generate_LOADV(
@@ -982,8 +982,9 @@ generate_LOADV(
        char_u      *name,
        int         error)
 {
-    // load v:var
-    int vidx = find_vim_var(name);
+    int            di_flags;
+    int            vidx = find_vim_var(name, &di_flags);
+    type_T  *type;
 
     RETURN_OK_IF_SKIP(cctx);
     if (vidx < 0)
@@ -992,9 +993,9 @@ generate_LOADV(
            semsg(_(e_var_notfound), name);
        return FAIL;
     }
+    type = typval2type(get_vim_var_tv(vidx));
 
-    // TODO: get actual type
-    return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, &t_any);
+    return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, type);
 }
 
 /*
@@ -3907,14 +3908,18 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
        }
        else if (STRNCMP(arg, "v:", 2) == 0)
        {
-           typval_T *vtv;
+           typval_T    *vtv;
+           int         di_flags;
 
-           vimvaridx = find_vim_var(name + 2);
+           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);