]> granicus.if.org Git - vim/commitdiff
patch 8.2.0467: Vim9: some errors are not tested v8.2.0467
authorBram Moolenaar <Bram@vim.org>
Sat, 28 Mar 2020 18:41:33 +0000 (19:41 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 28 Mar 2020 18:41:33 +0000 (19:41 +0100)
Problem:    Vim9: some errors are not tested
Solution:   Add more tests.  Fix that Vim9 script flag is not reset.

src/dict.c
src/scriptfile.c
src/testdir/test_vim9_expr.vim
src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index 2ff4ae37f782a4a3665867620042a5cdb94ec2b8..1a928a35f2094b0b8f447c36a694fc98a6f0b8ed 100644 (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);
index 55b1ddd26058c31f450d94acd61bfe8c65474c4c..a7af4e95bfd012416b2d97549a7b35a7b9ae87ab 100644 (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);
index d67c2d565c035a12d1c2be3462af02b0ec17167c..c9d50246dfe65ebb38e3f93bffe57364ac21e8bc 100644 (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
index 15b26403b7995dbc2ca4812930996759fa1457a6..5eeb19842fc322ad817f3d681d1d14d05f0e296d 100644 (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)
 
index 1630b5e709869ebf397e99551bd334956fe77f6f..863f5eedc35c907d1b09e98c2057da9ea9da8bde 100644 (file)
@@ -738,6 +738,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    467,
 /**/
     466,
 /**/
index 66eda7c916494d772b06e60cf502daf35689f702..12dae49dabac9d5e65e7d1f5747c03d172e76821 100644 (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;