]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.2.4484: Vim9: some error messages are not tested v8.2.4484
authorBram Moolenaar <Bram@vim.org>
Mon, 28 Feb 2022 20:55:02 +0000 (20:55 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 28 Feb 2022 20:55:02 +0000 (20:55 +0000)
Problem:    Vim9: some error messages are not tested.
Solution:   Add a few more test cases.  Delete dead code.

src/testdir/test_vim9_assign.vim
src/testdir/test_vim9_expr.vim
src/testdir/test_vim9_func.vim
src/version.c
src/vim9execute.c

index 44247add1f409ebea56e51ab31bd8fbdf88cd2b1..565d897bb3f63524158f828ecd4705ca7023c538 100644 (file)
@@ -550,6 +550,13 @@ def Test_assign_index()
   bl[-2] = 0x66
   assert_equal(0z77226644, bl)
 
+  lines =<< trim END
+      g:val = '22'
+      var bl = 0z11
+      bl[1] = g:val
+  END
+  v9.CheckDefExecAndScriptFailure(lines, 'E1030: Using a String as a Number: "22"')
+
   # should not read the next line when generating "a.b"
   var a = {}
   a.b = {}
@@ -1233,12 +1240,18 @@ def Test_script_var_default()
   var lines =<< trim END
       vim9script
       var l: list<number>
+      var li = [1, 2]
       var bl: blob
+      var bli = 0z12
       var d: dict<number>
+      var di = {'a': 1, 'b': 2}
       def Echo()
         assert_equal([], l)
+        assert_equal([1, 2], li)
         assert_equal(0z, bl)
+        assert_equal(0z12, bli)
         assert_equal({}, d)
+        assert_equal({'a': 1, 'b': 2}, di)
       enddef
       Echo()
   END
@@ -1502,6 +1515,30 @@ def Test_assign_list()
   END
   v9.CheckDefAndScriptSuccess(lines)
 
+  lines =<< trim END
+      var l = [1, 2]
+      g:idx = 'x'
+      l[g:idx : 1] = [0]
+      echo l
+  END
+  v9.CheckDefExecAndScriptFailure(lines, 'E1030: Using a String as a Number: "x"')
+
+  lines =<< trim END
+      var l = [1, 2]
+      g:idx = 3
+      l[g:idx : 1] = [0]
+      echo l
+  END
+  v9.CheckDefExecAndScriptFailure(lines, 'E684: list index out of range: 3')
+
+  lines =<< trim END
+      var l = [1, 2]
+      g:idx = 'y'
+      l[1 : g:idx] = [0]
+      echo l
+  END
+  v9.CheckDefExecAndScriptFailure(lines, ['E1012: Type mismatch; expected number but got string', 'E1030: Using a String as a Number: "y"'])
+
   v9.CheckDefFailure(["var l: list<number> = ['', true]"], 'E1012: Type mismatch; expected list<number> but got list<any>', 1)
   v9.CheckDefFailure(["var l: list<list<number>> = [['', true]]"], 'E1012: Type mismatch; expected list<list<number>> but got list<list<any>>', 1)
 enddef
index f9cb62cb0e0798ffb7c7eda8c3362668b253cb07..4aad9c98c9185cb2d71b689d3d7829f0d00eb321 100644 (file)
@@ -2782,6 +2782,23 @@ def Test_expr8_any_index_slice()
 
   v9.CheckDefAndScriptSuccess(lines)
 
+  lines =<< trim END
+      vim9script
+
+      def PosIdx(s: string): string
+        return s[1]
+      enddef
+      def NegIdx(s: string): string
+        return s[-1]
+      enddef
+
+      set enc=latin1
+      assert_equal("\xe4", PosIdx("a\xe4\xe5"))
+      assert_equal("\xe5", NegIdx("a\xe4\xe5"))
+      set enc=utf-8
+  END
+  v9.CheckScriptSuccess(lines)
+
   v9.CheckDefExecAndScriptFailure(['echo g:testblob[2]'], 'E979:', 1)
   v9.CheckDefExecAndScriptFailure(['echo g:testblob[-3]'], 'E979:', 1)
 
index 74883975bb3b179eca33d8e98e61379296b0960c..866cf4cc7f65bb8d7f29d917fdaa14909d6bf222 100644 (file)
@@ -550,6 +550,44 @@ def Test_call_ufunc_count()
   unlet g:counter
 enddef
 
+def Test_call_ufunc_failure()
+  var lines =<< trim END
+      vim9script
+      def Tryit()
+        g:Global(1, 2, 3)
+      enddef
+
+      func g:Global(a, b, c)
+        echo a:a a:b a:c
+      endfunc
+
+      defcompile
+
+      func! g:Global(a, b)
+        echo a:a a:b 
+      endfunc
+      Tryit()
+  END
+  v9.CheckScriptFailure(lines, 'E118: Too many arguments for function: Global')
+  delfunc g:Global
+
+  lines =<< trim END
+      vim9script
+
+      g:Ref = function('len')
+      def Tryit()
+        g:Ref('x')
+      enddef
+
+      defcompile
+
+      g:Ref = function('add')
+      Tryit()
+  END
+  v9.CheckScriptFailure(lines, 'E119: Not enough arguments for function: add')
+  unlet g:Ref
+enddef
+
 def s:MyVarargs(arg: string, ...rest: list<string>): string
   var res = arg
   for s in rest
index 9ba8bb9bbb6e501af2e065ce31c8da8a76a9d05d..c64bd83e97050b9d947b40068a9b4ae257e9eb6e 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4484,
 /**/
     4483,
 /**/
index beca9e723d9e5a3e6a17949b2c0fb2c1ebc9ba08..a7b76c639e15386347c4be3f00c99e2ef13061f8 100644 (file)
@@ -1027,7 +1027,7 @@ call_by_name(
     {
        int func_idx = find_internal_func(name);
 
-       if (func_idx < 0)
+       if (func_idx < 0)  // Impossible?
            return FAIL;
        if (check_internal_func(func_idx, argcount) < 0)
            return FAIL;
@@ -1452,8 +1452,6 @@ get_split_sourceline(
     char_u             *p;
     char_u             *line;
 
-    if (*sp->nextline == NUL)
-       return NULL;
     p = vim_strchr(sp->nextline, '\n');
     if (p == NULL)
     {
@@ -1911,11 +1909,11 @@ execute_storerange(isn_T *iptr, ectx_T *ectx)
            else
                n2 = (long)tv_get_number_chk(tv_idx2, &error);
            if (error)
-               status = FAIL;
+               status = FAIL; // cannot happen?
            else
            {
                listitem_T *li1 = check_range_index_one(
-                       tv_dest->vval.v_list, &n1, FALSE);
+                                            tv_dest->vval.v_list, &n1, FALSE);
 
                if (li1 == NULL)
                    status = FAIL;