changeset 19960:3c11b9f6fa03 v8.2.0536

patch 8.2.0536: Vim9: some compilation code not tested Commit: https://github.com/vim/vim/commit/5da356e07359a59cf2d682908ba8592a72d5d9cd Author: Bram Moolenaar <Bram@vim.org> Date: Thu Apr 9 19:34:43 2020 +0200 patch 8.2.0536: Vim9: some compilation code not tested Problem: Vim9: some compilation code not tested. Solution: Add more test cases.
author Bram Moolenaar <Bram@vim.org>
date Thu, 09 Apr 2020 19:45:04 +0200
parents 12eb22ecf35b
children 2a644fc09f28
files src/evalvars.c src/proto/evalvars.pro src/testdir/test_vim9_expr.vim src/version.c src/vim9compile.c
diffstat 5 files changed, 40 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -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);
 }
--- a/src/proto/evalvars.pro
+++ b/src/proto/evalvars.pro
@@ -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);
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -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:')
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    536,
+/**/
     535,
 /**/
     534,
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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;
     }
-
-    // TODO: get actual type
-    return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, &t_any);
+    type = typval2type(get_vim_var_tv(vidx));
+
+    return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, type);
 }
 
 /*
@@ -3907,14 +3908,18 @@ compile_assignment(char_u *arg, exarg_T 
 	}
 	else if (STRNCMP(arg, "v:", 2) == 0)
 	{
-	    typval_T *vtv;
-
-	    vimvaridx = find_vim_var(name + 2);
+	    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);