Skip to content

Commit 5da356e

Browse files
committed
patch 8.2.0536: Vim9: some compilation code not tested
Problem: Vim9: some compilation code not tested. Solution: Add more test cases.
1 parent 4d23c52 commit 5da356e

5 files changed

Lines changed: 38 additions & 13 deletions

File tree

src/evalvars.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,15 +1915,17 @@ get_vimvar_dict(void)
19151915

19161916
/*
19171917
* Returns the index of a v:variable. Negative if not found.
1918+
* Returns DI_ flags in "di_flags".
19181919
*/
19191920
int
1920-
find_vim_var(char_u *name)
1921+
find_vim_var(char_u *name, int *di_flags)
19211922
{
1922-
dictitem_T *di = find_var_in_ht(&vimvarht, 0, name, TRUE);
1923-
struct vimvar *vv;
1923+
dictitem_T *di = find_var_in_ht(&vimvarht, 0, name, TRUE);
1924+
struct vimvar *vv;
19241925

19251926
if (di == NULL)
19261927
return -1;
1928+
*di_flags = di->di_flags;
19271929
vv = (struct vimvar *)((char *)di - offsetof(vimvar_T, vv_di));
19281930
return (int)(vv - vimvars);
19291931
}

src/proto/evalvars.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ char *get_var_special_name(int nr);
2828
dict_T *get_globvar_dict(void);
2929
hashtab_T *get_globvar_ht(void);
3030
dict_T *get_vimvar_dict(void);
31-
int find_vim_var(char_u *name);
31+
int find_vim_var(char_u *name, int *di_flags);
3232
void set_vim_var_type(int idx, vartype_T type);
3333
void set_vim_var_nr(int idx, varnumber_T val);
3434
char *get_vim_var_name(int idx);

src/testdir/test_vim9_expr.vim

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,12 +711,28 @@ def Test_expr7_string()
711711
call CheckDefFailure("let x = 'abc", 'E115:')
712712
enddef
713713

714+
def Test_expr7_vimvar()
715+
let old: list<string> = v:oldfiles
716+
let compl: dict<any> = v:completed_item
717+
718+
call CheckDefFailure("let old: list<number> = v:oldfiles", 'E1013: type mismatch, expected list<number> but got list<string>')
719+
call CheckDefFailure("let old: dict<number> = v:completed_item", 'E1013: type mismatch, expected dict<number> but got dict<any>')
720+
enddef
721+
714722
def Test_expr7_special()
715723
" special constant
716724
assert_equal(g:special_true, true)
717725
assert_equal(g:special_false, false)
726+
assert_equal(g:special_true, v:true)
727+
assert_equal(g:special_false, v:false)
718728
assert_equal(g:special_null, v:null)
719729
assert_equal(g:special_none, v:none)
730+
731+
call CheckDefFailure('v:true = true', 'E46:')
732+
call CheckDefFailure('v:true = false', 'E46:')
733+
call CheckDefFailure('v:false = true', 'E46:')
734+
call CheckDefFailure('v:null = 11', 'E46:')
735+
call CheckDefFailure('v:none = 22', 'E46:')
720736
enddef
721737

722738
def Test_expr7_list()
@@ -962,7 +978,7 @@ func Test_expr_fails()
962978
call CheckDefFailure("CallMe2('yes' , 'no')", 'E1068:')
963979

964980
call CheckDefFailure("v:nosuch += 3", 'E1001:')
965-
call CheckDefFailure("let v:version = 3", 'E1064:')
981+
call CheckDefFailure("let v:statusmsg = ''", 'E1064:')
966982
call CheckDefFailure("let asdf = v:nosuch", 'E1001:')
967983

968984
call CheckDefFailure("echo len('asdf'", 'E110:')

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,8 @@ static char *(features[]) =
738738

739739
static int included_patches[] =
740740
{ /* Add new patch number below this line */
741+
/**/
742+
536,
741743
/**/
742744
535,
743745
/**/

src/vim9compile.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ typval2type(typval_T *tv)
403403
return &t_list_string;
404404
if (tv->v_type == VAR_DICT) // e.g. for v:completed_item
405405
return &t_dict_any;
406-
return &t_any;
406+
return &t_any; // not used
407407
}
408408

409409
/////////////////////////////////////////////////////////////////////
@@ -974,16 +974,17 @@ generate_LOAD(
974974
}
975975

976976
/*
977-
* Generate an ISN_LOADV instruction.
977+
* Generate an ISN_LOADV instruction for v:var.
978978
*/
979979
static int
980980
generate_LOADV(
981981
cctx_T *cctx,
982982
char_u *name,
983983
int error)
984984
{
985-
// load v:var
986-
int vidx = find_vim_var(name);
985+
int di_flags;
986+
int vidx = find_vim_var(name, &di_flags);
987+
type_T *type;
987988

988989
RETURN_OK_IF_SKIP(cctx);
989990
if (vidx < 0)
@@ -992,9 +993,9 @@ generate_LOADV(
992993
semsg(_(e_var_notfound), name);
993994
return FAIL;
994995
}
996+
type = typval2type(get_vim_var_tv(vidx));
995997

996-
// TODO: get actual type
997-
return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, &t_any);
998+
return generate_LOAD(cctx, ISN_LOADV, vidx, NULL, type);
998999
}
9991000

10001001
/*
@@ -3907,14 +3908,18 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
39073908
}
39083909
else if (STRNCMP(arg, "v:", 2) == 0)
39093910
{
3910-
typval_T *vtv;
3911+
typval_T *vtv;
3912+
int di_flags;
39113913

3912-
vimvaridx = find_vim_var(name + 2);
3914+
vimvaridx = find_vim_var(name + 2, &di_flags);
39133915
if (vimvaridx < 0)
39143916
{
39153917
semsg(_(e_var_notfound), arg);
39163918
goto theend;
39173919
}
3920+
// We use the current value of "sandbox" here, is that OK?
3921+
if (var_check_ro(di_flags, name, FALSE))
3922+
goto theend;
39183923
dest = dest_vimvar;
39193924
vtv = get_vim_var_tv(vimvaridx);
39203925
type = typval2type(vtv);

0 commit comments

Comments
 (0)