To: vim_dev@googlegroups.com Subject: Patch 8.2.2184 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2184 Problem: Vim9: no error when using "2" for a line number. Solution: Give an error message if the line number is invalid. (closes #7492) Files: src/typval.c, src/evalfunc.c, src/testdir/test_vim9_builtin.vim, src/testdir/test_cursor_func.vim *** ../vim-8.2.2183/src/typval.c 2020-12-12 18:58:36.784284038 +0100 --- src/typval.c 2020-12-21 21:51:37.377264516 +0100 *************** *** 1536,1546 **** linenr_T tv_get_lnum(typval_T *argvars) { ! linenr_T lnum = 0; if (argvars[0].v_type != VAR_STRING || !in_vim9script()) lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL); ! if (lnum == 0) // no valid number, try using arg like line() { int fnum; pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum); --- 1536,1546 ---- linenr_T tv_get_lnum(typval_T *argvars) { ! linenr_T lnum = -1; if (argvars[0].v_type != VAR_STRING || !in_vim9script()) lnum = (linenr_T)tv_get_number_chk(&argvars[0], NULL); ! if (lnum <= 0) // no valid number, try using arg like line() { int fnum; pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum); *** ../vim-8.2.2183/src/evalfunc.c 2020-11-16 20:08:32.395713947 +0100 --- src/evalfunc.c 2020-12-21 21:31:41.098593477 +0100 *************** *** 2615,2620 **** --- 2615,2622 ---- else { line = tv_get_lnum(argvars); + if (line < 0) + semsg(_(e_invarg2), tv_get_string(&argvars[0])); col = (long)tv_get_number_chk(&argvars[1], NULL); if (argvars[2].v_type != VAR_UNKNOWN) coladd = (long)tv_get_number_chk(&argvars[2], NULL); *** ../vim-8.2.2183/src/testdir/test_vim9_builtin.vim 2020-12-12 18:58:36.788284026 +0100 --- src/testdir/test_vim9_builtin.vim 2020-12-21 21:37:59.604624841 +0100 *************** *** 185,190 **** --- 185,204 ---- count('ABC ABC ABC', 'b', false)->assert_equal(0) enddef + def Test_cursor() + new + setline(1, range(4)) + cursor(2, 1) + assert_equal(2, getcurpos()[1]) + cursor('$', 1) + assert_equal(4, getcurpos()[1]) + + var lines =<< trim END + cursor('2', 1) + END + CheckDefExecAndScriptFailure(lines, 'E475:') + enddef + def Test_executable() assert_false(executable("")) assert_false(executable(test_null_string())) *** ../vim-8.2.2183/src/testdir/test_cursor_func.vim 2020-12-17 21:35:25.747874396 +0100 --- src/testdir/test_cursor_func.vim 2020-12-21 21:57:43.239905121 +0100 *************** *** 30,36 **** call cursor(1, 1, 1) call assert_equal([1, 1, 1], getcurpos()[1:3]) ! call assert_equal(-1, cursor(-1, -1)) quit! endfunc --- 30,36 ---- call cursor(1, 1, 1) call assert_equal([1, 1, 1], getcurpos()[1:3]) ! call assert_fails('call cursor(-1, -1)', 'E475:') quit! endfunc *** ../vim-8.2.2183/src/version.c 2020-12-21 20:32:40.126103572 +0100 --- src/version.c 2020-12-21 21:21:14.677130294 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2184, /**/ -- I learned the customs and mannerisms of engineers by observing them, much the way Jane Goodall learned about the great apes, but without the hassle of grooming. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///