changeset 29922:b366b19d1a3e v9.0.0299

patch 9.0.0299: error messages for setcmdline() could be better Commit: https://github.com/vim/vim/commit/25f1e5556259d536c8608185145b0769262873ff Author: Yegappan Lakshmanan <yegappan@yahoo.com> Date: Sun Aug 28 17:25:04 2022 +0100 patch 9.0.0299: error messages for setcmdline() could be better Problem: Error messages for setcmdline() could be better. Solution: Use more specific error messages. (Yegappan Lakshmanan, closes #10995)
author Bram Moolenaar <Bram@vim.org>
date Sun, 28 Aug 2022 18:30:02 +0200
parents f529c18aa16a
children efd2c441a694
files src/ex_getln.c src/testdir/test_cmdline.vim src/testdir/test_vim9_builtin.vim src/version.c
diffstat 4 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/ex_getln.c
+++ b/src/ex_getln.c
@@ -4272,11 +4272,9 @@ f_setcmdline(typval_T *argvars, typval_T
 {
     int pos = -1;
 
-    if (argvars[0].v_type != VAR_STRING || argvars[0].vval.v_string == NULL)
-    {
-	emsg(_(e_string_required));
+    if (check_for_string_arg(argvars, 0) == FAIL
+	    || check_for_opt_number_arg(argvars, 1) == FAIL)
 	return;
-    }
 
     if (argvars[1].v_type != VAR_UNKNOWN)
     {
--- a/src/testdir/test_cmdline.vim
+++ b/src/testdir/test_cmdline.vim
@@ -3273,8 +3273,8 @@ func Test_setcmdline()
     call assert_equal(a:pos, getcmdpos())
 
     call assert_fails('call setcmdline("' .. a:text .. '", -1)', 'E487:')
-    call assert_fails('call setcmdline({}, 0)', 'E928:')
-    call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E728:')
+    call assert_fails('call setcmdline({}, 0)', 'E1174:')
+    call assert_fails('call setcmdline("' .. a:text .. '", {})', 'E1210:')
 
     return ''
   endfunc
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -3659,8 +3659,8 @@ enddef
 
 def Test_setcmdline()
   v9.CheckDefAndScriptSuccess(['setcmdline("ls", 2)'])
-  v9.CheckDefAndScriptFailure(['setcmdline(123)'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E928: String required'])
-  v9.CheckDefAndScriptFailure(['setcmdline("ls", "x")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1030: Using a String as a Number'])
+  v9.CheckDefAndScriptFailure(['setcmdline(123)'], ['E1013: Argument 1: type mismatch, expected string but got number', 'E1174: String required for argument 1'])
+  v9.CheckDefAndScriptFailure(['setcmdline("ls", "x")'], ['E1013: Argument 2: type mismatch, expected number but got string', 'E1210: Number required for argument 2'])
 enddef
 
 def Test_setcmdpos()
--- a/src/version.c
+++ b/src/version.c
@@ -708,6 +708,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    299,
+/**/
     298,
 /**/
     297,