# HG changeset patch # User Bram Moolenaar # Date 1646082002 -3600 # Node ID 7d70b420de00c06d31256c57c3e74eb576b3a4eb # Parent ab7bfb80c2c0b09b1410977e0d77bcefcd65f79c patch 8.2.4484: Vim9: some error messages are not tested Commit: https://github.com/vim/vim/commit/1983f1aa315711852174be1b7089f71e24c19e27 Author: Bram Moolenaar Date: Mon Feb 28 20:55:02 2022 +0000 patch 8.2.4484: Vim9: some error messages are not tested Problem: Vim9: some error messages are not tested. Solution: Add a few more test cases. Delete dead code. diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -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 + 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,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 = ['', 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 diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim --- a/src/testdir/test_vim9_expr.vim +++ b/src/testdir/test_vim9_expr.vim @@ -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) diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim --- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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 var res = arg for s in rest diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4484, +/**/ 4483, /**/ 4482, diff --git a/src/vim9execute.c b/src/vim9execute.c --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -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 * 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;