summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-04-09 19:34:43 +0200
committerBram Moolenaar <Bram@vim.org>2020-04-09 19:34:43 +0200
commit5da356e07359a59cf2d682908ba8592a72d5d9cd (patch)
tree7769114608235782984c94061cef30c974537ba4
parent4d23c52824dd2f4577eb980e7d91feed34052755 (diff)
downloadvim-git-5da356e07359a59cf2d682908ba8592a72d5d9cd.tar.gz
patch 8.2.0536: Vim9: some compilation code not testedv8.2.0536
Problem: Vim9: some compilation code not tested. Solution: Add more test cases.
-rw-r--r--src/evalvars.c8
-rw-r--r--src/proto/evalvars.pro2
-rw-r--r--src/testdir/test_vim9_expr.vim18
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c21
5 files changed, 38 insertions, 13 deletions
diff --git a/src/evalvars.c b/src/evalvars.c
index 6b9c270a3..8af80ec0a 100644
--- 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);
}
diff --git a/src/proto/evalvars.pro b/src/proto/evalvars.pro
index 4338b20f7..352097d43 100644
--- 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);
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index f11fc8389..f34041b5d 100644
--- 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:')
diff --git a/src/version.c b/src/version.c
index 78bb33262..1faac9606 100644
--- 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,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index a8a764746..0bc50c3e0 100644
--- 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;
}
+ 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);