0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.0467: Vim9: some errors are not tested

Problem:    Vim9: some errors are not tested
Solution:   Add more tests.  Fix that Vim9 script flag is not reset.
This commit is contained in:
Bram Moolenaar 2020-03-28 19:41:33 +01:00
parent 09c569038c
commit 33fa29cf74
6 changed files with 61 additions and 7 deletions

View File

@ -826,7 +826,8 @@ eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal)
if (**arg != ':')
{
semsg(_(e_missing_dict_colon), *arg);
if (evaluate)
semsg(_(e_missing_dict_colon), *arg);
clear_tv(&tvkey);
goto failret;
}
@ -853,7 +854,8 @@ eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal)
item = dict_find(d, key, -1);
if (item != NULL)
{
semsg(_(e_duplicate_key), key);
if (evaluate)
semsg(_(e_duplicate_key), key);
clear_tv(&tvkey);
clear_tv(&tv);
goto failret;
@ -873,7 +875,8 @@ eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal)
break;
if (**arg != ',')
{
semsg(_(e_missing_dict_comma), *arg);
if (evaluate)
semsg(_(e_missing_dict_comma), *arg);
goto failret;
}
*arg = skipwhite(*arg + 1);
@ -881,7 +884,8 @@ eval_dict(char_u **arg, typval_T *rettv, int evaluate, int literal)
if (**arg != '}')
{
semsg(_(e_missing_dict_end), *arg);
if (evaluate)
semsg(_(e_missing_dict_end), *arg);
failret:
if (d != NULL)
dict_free(d);

View File

@ -1274,6 +1274,7 @@ do_source(
// loading the same script again
si->sn_had_command = FALSE;
si->sn_version = 1;
current_sctx.sc_sid = sid;
ht = &SCRIPT_VARS(sid);

View File

@ -812,12 +812,25 @@ func Test_expr7_fails()
call CheckDefExecFailure("echo s:doesnt_exist", 'E121:')
call CheckDefExecFailure("echo g:doesnt_exist", 'E121:')
call CheckDefFailure("echo a:somevar", 'E1075:')
call CheckDefFailure("echo l:somevar", 'E1075:')
call CheckDefFailure("echo x:somevar", 'E1075:')
" TODO
call CheckDefFailure("echo b:somevar", 'not supported yet')
call CheckDefFailure("echo w:somevar", 'not supported yet')
call CheckDefFailure("echo t:somevar", 'not supported yet')
call CheckDefExecFailure("let x = +g:astring", 'E1030:')
call CheckDefExecFailure("let x = +g:ablob", 'E974:')
call CheckDefExecFailure("let x = +g:alist", 'E745:')
call CheckDefExecFailure("let x = +g:adict", 'E728:')
call CheckDefFailureMult(["let x = ''", "let y = x.memb"], 'E715:')
call CheckDefExecFailure("[1, 2->len()", 'E492:')
call CheckDefExecFailure("#{a: 1->len()", 'E488:')
call CheckDefExecFailure("{'a': 1->len()", 'E492:')
endfunc
let g:Funcrefs = [function('add')]
@ -878,4 +891,8 @@ func Test_expr_fails()
call CheckDefFailure("v:nosuch += 3", 'E1001:')
call CheckDefFailure("let v:version = 3", 'E1064:')
call CheckDefFailure("let asdf = v:nosuch", 'E1001:')
call CheckDefFailure("echo len('asdf'", 'E110:')
call CheckDefFailure("echo Func0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789()", 'E1011:')
call CheckDefFailure("echo doesnotexist()", 'E117:')
endfunc

View File

@ -101,6 +101,8 @@ func Test_assignment_failure()
call CheckDefFailure(['let true = 1'], 'E1034:')
call CheckDefFailure(['let false = 1'], 'E1034:')
call CheckScriptFailure(['vim9script', 'def Func()', 'let dummy = s:notfound', 'enddef'], 'E1050:')
call CheckDefFailure(['let var: list<string> = [123]'], 'expected list<string> but got list<number>')
call CheckDefFailure(['let var: list<number> = ["xx"]'], 'expected list<number> but got list<string>')
@ -618,6 +620,12 @@ def Test_vim9script_call()
enddef
{'a': 1, 'b': 2}->DictFunc()
assert_equal(#{a: 1, b: 2}, dictvar)
def CompiledDict()
{'a': 3, 'b': 4}->DictFunc()
enddef
CompiledDict()
assert_equal(#{a: 3, b: 4}, dictvar)
#{a: 3, b: 4}->DictFunc()
assert_equal(#{a: 3, b: 4}, dictvar)

View File

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

View File

@ -1815,7 +1815,10 @@ compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error)
if (*(*arg + 1) == ':')
{
// load namespaced variable
name = vim_strnsave(*arg + 2, end - (*arg + 2));
if (end <= *arg + 2)
name = vim_strsave((char_u *)"[empty]");
else
name = vim_strnsave(*arg + 2, end - (*arg + 2));
if (name == NULL)
return FAIL;
@ -1833,9 +1836,24 @@ compile_load(char_u **arg, char_u *end_arg, cctx_T *cctx, int error)
{
res = compile_load_scriptvar(cctx, name, NULL, NULL, error);
}
else if (**arg == 'b')
{
semsg("Namespace b: not supported yet: %s", *arg);
goto theend;
}
else if (**arg == 'w')
{
semsg("Namespace w: not supported yet: %s", *arg);
goto theend;
}
else if (**arg == 't')
{
semsg("Namespace t: not supported yet: %s", *arg);
goto theend;
}
else
{
semsg("Namespace not supported yet: %s", *arg);
semsg("E1075: Namespace not supported: %s", *arg);
goto theend;
}
}
@ -2060,6 +2078,7 @@ to_name_const_end(char_u *arg)
}
else if (p == arg && *arg == '#' && arg[1] == '{')
{
// Can be "#{a: 1}->Func()".
++p;
if (eval_dict(&p, &rettv, FALSE, TRUE) == FAIL)
p = arg;
@ -2068,6 +2087,8 @@ to_name_const_end(char_u *arg)
{
int ret = get_lambda_tv(&p, &rettv, FALSE);
// Can be "{x -> ret}()".
// Can be "{'a': 1}->Func()".
if (ret == NOTDONE)
ret = eval_dict(&p, &rettv, FALSE, FALSE);
if (ret != OK)
@ -5123,7 +5144,8 @@ compile_def_function(ufunc_T *ufunc, int set_return_type)
}
// "{" starts a block scope
if (*ea.cmd == '{')
// "{'a': 1}->func() is something else
if (*ea.cmd == '{' && ends_excmd(*skipwhite(ea.cmd + 1)))
{
line = compile_block(ea.cmd, &cctx);
continue;