Mercurial > vim
changeset 19822:fc3cdc819d80 v8.2.0467
patch 8.2.0467: Vim9: some errors are not tested
Commit: https://github.com/vim/vim/commit/33fa29cf74ea314f89cfa58ec9ffc2d6781a59d4
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Mar 28 19:41:33 2020 +0100
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 28 Mar 2020 19:45:04 +0100 |
parents | 54157d9d75c7 |
children | fafab4bec82f |
files | src/dict.c src/scriptfile.c src/testdir/test_vim9_expr.vim src/testdir/test_vim9_script.vim src/version.c src/vim9compile.c |
diffstat | 6 files changed, 61 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dict.c +++ b/src/dict.c @@ -826,7 +826,8 @@ eval_dict(char_u **arg, typval_T *rettv, 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, 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, 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, if (**arg != '}') { - semsg(_(e_missing_dict_end), *arg); + if (evaluate) + semsg(_(e_missing_dict_end), *arg); failret: if (d != NULL) dict_free(d);
--- a/src/scriptfile.c +++ b/src/scriptfile.c @@ -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);
--- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -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
--- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -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)
--- 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 */ /**/ + 467, +/**/ 466, /**/ 465,
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1815,7 +1815,10 @@ compile_load(char_u **arg, char_u *end_a 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_a { 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 } // "{" 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;