diff options
-rw-r--r-- | src/dict.c | 12 | ||||
-rw-r--r-- | src/scriptfile.c | 1 | ||||
-rw-r--r-- | src/testdir/test_vim9_expr.vim | 17 | ||||
-rw-r--r-- | src/testdir/test_vim9_script.vim | 8 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 28 |
6 files changed, 61 insertions, 7 deletions
diff --git a/src/dict.c b/src/dict.c index 2ff4ae37f..1a928a35f 100644 --- a/src/dict.c +++ b/src/dict.c @@ -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); diff --git a/src/scriptfile.c b/src/scriptfile.c index 55b1ddd26..a7af4e95b 100644 --- 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); diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim index d67c2d565..c9d50246d 100644 --- 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 diff --git a/src/testdir/test_vim9_script.vim b/src/testdir/test_vim9_script.vim index 15b26403b..5eeb19842 100644 --- 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) diff --git a/src/version.c b/src/version.c index 1630b5e70..863f5eedc 100644 --- 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, diff --git a/src/vim9compile.c b/src/vim9compile.c index 66eda7c91..12dae49da 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -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; |