Problem: Vim9: some compilation code not tested.
Solution: Add more test cases.
/*
* 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);
}
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);
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()
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:')
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 536,
/**/
535,
/**/
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
}
/////////////////////////////////////////////////////////////////////
}
/*
- * Generate an ISN_LOADV instruction.
+ * Generate an ISN_LOADV instruction for v:var.
*/
static int
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)
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);
}
/*
}
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);