To: vim_dev@googlegroups.com Subject: Patch 8.2.4484 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4484 Problem: Vim9: some error messages are not tested. Solution: Add a few more test cases. Delete dead code. Files: src/vim9execute.c, src/testdir/test_vim9_assign.vim, src/testdir/test_vim9_expr.vim, src/testdir/test_vim9_func.vim *** ../vim-8.2.4483/src/vim9execute.c 2022-02-22 19:39:07.590366896 +0000 --- src/vim9execute.c 2022-02-28 20:35:21.586573789 +0000 *************** *** 1027,1033 **** { int func_idx = find_internal_func(name); ! if (func_idx < 0) return FAIL; if (check_internal_func(func_idx, argcount) < 0) return FAIL; --- 1027,1033 ---- { int func_idx = find_internal_func(name); ! if (func_idx < 0) // Impossible? return FAIL; if (check_internal_func(func_idx, argcount) < 0) return FAIL; *************** *** 1452,1459 **** char_u *p; char_u *line; - if (*sp->nextline == NUL) - return NULL; p = vim_strchr(sp->nextline, '\n'); if (p == NULL) { --- 1452,1457 ---- *************** *** 1911,1921 **** else n2 = (long)tv_get_number_chk(tv_idx2, &error); if (error) ! status = FAIL; else { listitem_T *li1 = check_range_index_one( ! tv_dest->vval.v_list, &n1, FALSE); if (li1 == NULL) status = FAIL; --- 1909,1919 ---- else n2 = (long)tv_get_number_chk(tv_idx2, &error); if (error) ! status = FAIL; // cannot happen? else { listitem_T *li1 = check_range_index_one( ! tv_dest->vval.v_list, &n1, FALSE); if (li1 == NULL) status = FAIL; *** ../vim-8.2.4483/src/testdir/test_vim9_assign.vim 2022-02-22 20:42:50.382992530 +0000 --- src/testdir/test_vim9_assign.vim 2022-02-28 20:38:31.445869269 +0000 *************** *** 550,555 **** --- 550,562 ---- 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,1244 **** --- 1240,1257 ---- var lines =<< trim END vim9script var l: list + var li = [1, 2] var bl: blob + var bli = 0z12 var d: dict + 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,1507 **** --- 1515,1544 ---- 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 = ['', true]"], 'E1012: Type mismatch; expected list but got list', 1) v9.CheckDefFailure(["var l: list> = [['', true]]"], 'E1012: Type mismatch; expected list> but got list>', 1) enddef *** ../vim-8.2.4483/src/testdir/test_vim9_expr.vim 2022-02-26 11:46:09.510212631 +0000 --- src/testdir/test_vim9_expr.vim 2022-02-28 19:13:35.770634230 +0000 *************** *** 2782,2787 **** --- 2782,2804 ---- 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) *** ../vim-8.2.4483/src/testdir/test_vim9_func.vim 2022-02-23 22:11:58.778087741 +0000 --- src/testdir/test_vim9_func.vim 2022-02-28 18:49:12.172334279 +0000 *************** *** 550,555 **** --- 550,593 ---- 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 var res = arg for s in rest *** ../vim-8.2.4483/src/version.c 2022-02-28 13:28:34.544563774 +0000 --- src/version.c 2022-02-28 18:40:10.471115994 +0000 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 4484, /**/ -- You cannot have a baby in one month by getting nine women pregnant. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///