0
0
mirror of https://github.com/vim/vim.git synced 2025-09-23 03:43:49 -04:00

patch 8.2.0536: Vim9: some compilation code not tested

Problem:    Vim9: some compilation code not tested.
Solution:   Add more test cases.
This commit is contained in:
Bram Moolenaar
2020-04-09 19:34:43 +02:00
parent 4d23c52824
commit 5da356e073
5 changed files with 38 additions and 13 deletions

View 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;
if (di == NULL)
return -1;
*di_flags = di->di_flags;
vv = (struct vimvar *)((char *)di - offsetof(vimvar_T, vv_di));
return (int)(vv - vimvars);
}

View 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);

View 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:')

View File

@@ -738,6 +738,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
536,
/**/
535,
/**/

View 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);
}
/*
@@ -3908,13 +3909,17 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
else if (STRNCMP(arg, "v:", 2) == 0)
{
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);