]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.1011: Vim9: some code not tested v8.2.1011
authorBram Moolenaar <Bram@vim.org>
Fri, 19 Jun 2020 16:34:15 +0000 (18:34 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 19 Jun 2020 16:34:15 +0000 (18:34 +0200)
Problem:    Vim9: some code not tested.
Solution:   Add a few more test cases.  Reorder checks for clearer error.
            Remove unreachable code.

src/evalvars.c
src/proto/vim9script.pro
src/testdir/test_vim9_expr.vim
src/testdir/test_vim9_script.vim
src/version.c
src/vim9execute.c
src/vim9script.c

index 0a0bbc44abc77be08ddaa26be045fdba87be58d3..fa52e96cd362d88ed0e3410d65ba5cc4a1cba7e5 100644 (file)
@@ -2886,10 +2886,6 @@ set_var_const(
                return;
            }
 
-           if (var_check_ro(di->di_flags, name, FALSE)
-                              || var_check_lock(di->di_tv.v_lock, name, FALSE))
-               return;
-
            if (is_script_local
                             && current_sctx.sc_version == SCRIPT_VERSION_VIM9)
            {
@@ -2900,8 +2896,13 @@ set_var_const(
                }
 
                // check the type
-               check_script_var_type(&di->di_tv, tv, name);
+               if (check_script_var_type(&di->di_tv, tv, name) == FAIL)
+                   return;
            }
+
+           if (var_check_ro(di->di_flags, name, FALSE)
+                              || var_check_lock(di->di_tv.v_lock, name, FALSE))
+               return;
        }
        else
            // can only redefine once
index 3a7b6e1719ac04fb3eae554d7f904982d111611c..a11f6af7a5f30984c497da6bd338f76b7c7f1013 100644 (file)
@@ -7,5 +7,5 @@ void ex_import(exarg_T *eap);
 int find_exported(int sid, char_u **argp, int *name_len, ufunc_T **ufunc, type_T **type);
 char_u *handle_import(char_u *arg_start, garray_T *gap, int import_sid, void *cctx);
 char_u *vim9_declare_scriptvar(exarg_T *eap, char_u *arg);
-void check_script_var_type(typval_T *dest, typval_T *value, char_u *name);
+int check_script_var_type(typval_T *dest, typval_T *value, char_u *name);
 /* vim: set ft=c : */
index e0776b53130b427fc73e7aba3bed503b9dc58378..224f4fda07c1b553ebb3b8b8ffded8e70cf4b12a 100644 (file)
@@ -524,6 +524,7 @@ def Test_expr5()
                        g:anint)
   assert_equal(9, g:alsoint + 5)
   assert_equal(14, g:alsoint + g:anint)
+  assert_equal([1, 2, 3, 4], [1] + g:alist)
 
   assert_equal(54, 60 - 6)
   assert_equal(50, 60 -
index 25fed4acd1f6cb9ab651d95ed6250e5ead15710f..3cfacbb84319ce17a55871330c6e04e68d75c9b6 100644 (file)
@@ -140,6 +140,9 @@ def Test_assignment_dict()
   let dict4: dict<any> = #{one: 1, two: '2'}
   let dict5: dict<blob> = #{one: 0z01, two: 0z02}
 
+  " overwrite
+  dict3['key'] = 'another'
+
   call CheckDefExecFailure(['let dd = {}', 'dd[""] = 6'], 'E713:')
 
   # type becomes dict<any>
@@ -219,6 +222,13 @@ def Test_assignment_default()
 
     let thechannel: channel
     assert_equal(test_null_channel(), thechannel)
+
+    if has('unix') && executable('cat')
+      " check with non-null job and channel, types must match
+      thejob = job_start("cat ", #{})
+      thechannel = job_getchannel(thejob)
+      job_stop(thejob, 'kill')
+    endif
   endif
 
   let nr = 1234 | nr = 5678
@@ -775,6 +785,9 @@ def Test_vim9script_fails()
   CheckScriptFailure(['vim9script', 'export let g:some'], 'E1044:')
   CheckScriptFailure(['vim9script', 'export echo 134'], 'E1043:')
 
+  CheckScriptFailure(['vim9script', 'let str: string', 'str = 1234'], 'E1013:')
+  CheckScriptFailure(['vim9script', 'const str = "asdf"', 'str = "xxx"'], 'E46:')
+
   assert_fails('vim9script', 'E1038')
   assert_fails('export something', 'E1043')
 enddef
index f1e274ad0a80193e33e98b03adc368fbda73c46e..cc580fb855154ed1113186416235af141ab67fc2 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1011,
 /**/
     1010,
 /**/
index 53a30c9b4372212edcb58665ea38197e1314b3ec..4271f3895bfc3349ce7491f03f3a4ff141b42c78 100644 (file)
@@ -2144,18 +2144,10 @@ call_def_function(
                    listitem_T  *li;
                    int         index = iptr->isn_arg.number;
 
-                   // get list item: list is at stack-1, push item
+                   // Get list item: list is at stack-1, push item.
+                   // List type and length is checked for when compiling.
                    tv = STACK_TV_BOT(-1);
-                   if (tv->v_type != VAR_LIST)
-                   {
-                       emsg(_(e_listreq));
-                       goto failed;
-                   }
-                   if ((li = list_find(tv->vval.v_list, index)) == NULL)
-                   {
-                       semsg(_(e_listidx), index);
-                       goto failed;
-                   }
+                   li = list_find(tv->vval.v_list, index);
 
                    if (GA_GROW(&ectx.ec_stack, 1) == FAIL)
                        goto failed;
index 442158c48e6531ba299ee4e02140e86517758fce..6c4cbc4305b55ff1adad49f0bcb0be9817e8cb4e 100644 (file)
@@ -507,7 +507,7 @@ vim9_declare_scriptvar(exarg_T *eap, char_u *arg)
 /*
  * Check if the type of script variable "dest" allows assigning "value".
  */
-    void
+    int
 check_script_var_type(typval_T *dest, typval_T *value, char_u *name)
 {
     scriptitem_T    *si = SCRIPT_ITEM(current_sctx.sc_sid);
@@ -521,13 +521,15 @@ check_script_var_type(typval_T *dest, typval_T *value, char_u *name)
        if (sv->sv_tv == dest)
        {
            if (sv->sv_const)
+           {
                semsg(_(e_readonlyvar), name);
-           else
-               check_type(sv->sv_type, typval2type(value), TRUE);
-           return;
+               return FAIL;
+           }
+           return check_type(sv->sv_type, typval2type(value), TRUE);
        }
     }
     iemsg("check_script_var_type(): not found");
+    return OK; // not really
 }
 
 #endif // FEAT_EVAL