Patch 8.2.3919
Problem: Vim9: wrong argument for append() results in two errors.
Solution: Check did_emsg. Also for setline(). Adjust the help for
appendbufline().
Files: runtime/doc/builtin.txt, src/evalbuffer.c, src/typval.c,
src/testdir/test_vim9_builtin.vim
*** ../vim-8.2.3918/runtime/doc/builtin.txt 2021-12-27 21:26:38.964743253
+0000
--- runtime/doc/builtin.txt 2021-12-28 11:07:57.630282485 +0000
***************
*** 806,814 ****
For the use of {buf}, see |bufname()|.
! {lnum} is used like with |append()|. Note that using |line()|
! would use the current buffer, not the one appending to.
! Use "$" to append at the end of the buffer.
On success 0 is returned, on failure 1 is returned.
In |Vim9| script an error is given for an invalid {lnum}.
--- 806,815 ----
For the use of {buf}, see |bufname()|.
! {lnum} is the line number to append below. Note that using
! |line()| would use the current buffer, not the one appending
! to. Use "$" to append at the end of the buffer. Other string
! values are not supported.
On success 0 is returned, on failure 1 is returned.
In |Vim9| script an error is given for an invalid {lnum}.
*** ../vim-8.2.3918/src/evalbuffer.c 2021-12-27 20:57:03.483387913 +0000
--- src/evalbuffer.c 2021-12-28 11:22:06.265309712 +0000
***************
*** 274,285 ****
f_append(typval_T *argvars, typval_T *rettv)
{
linenr_T lnum;
if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL)
return;
lnum = tv_get_lnum(&argvars[0]);
! set_buffer_lines(curbuf, lnum, TRUE, &argvars[1], rettv);
}
/*
--- 274,287 ----
f_append(typval_T *argvars, typval_T *rettv)
{
linenr_T lnum;
+ int did_emsg_before = did_emsg;
if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL)
return;
lnum = tv_get_lnum(&argvars[0]);
! if (did_emsg == did_emsg_before)
! set_buffer_lines(curbuf, lnum, TRUE, &argvars[1], rettv);
}
/*
***************
*** 290,295 ****
--- 292,298 ----
{
linenr_T lnum;
buf_T *buf;
+ int did_emsg_before = did_emsg;
if (in_vim9script()
&& (check_for_buffer_arg(argvars, 0) == FAIL
***************
*** 303,309 ****
else
{
lnum = tv_get_lnum_buf(&argvars[1], buf);
! set_buffer_lines(buf, lnum, append, &argvars[2], rettv);
}
}
--- 306,313 ----
else
{
lnum = tv_get_lnum_buf(&argvars[1], buf);
! if (did_emsg == did_emsg_before)
! set_buffer_lines(buf, lnum, append, &argvars[2], rettv);
}
}
***************
*** 502,507 ****
--- 506,514 ----
win_T *curwin_save = NULL;
tabpage_T *tp;
win_T *wp;
+ int did_emsg_before = did_emsg;
+
+ rettv->vval.v_number = 1; // FAIL by default
if (in_vim9script()
&& (check_for_buffer_arg(argvars, 0) == FAIL
***************
*** 511,523 ****
buf = tv_get_buf(&argvars[0], FALSE);
if (buf == NULL)
- {
- rettv->vval.v_number = 1; // FAIL
return;
- }
is_curbuf = buf == curbuf;
first = tv_get_lnum_buf(&argvars[1], buf);
if (argvars[2].v_type != VAR_UNKNOWN)
last = tv_get_lnum_buf(&argvars[2], buf);
else
--- 518,529 ----
buf = tv_get_buf(&argvars[0], FALSE);
if (buf == NULL)
return;
is_curbuf = buf == curbuf;
first = tv_get_lnum_buf(&argvars[1], buf);
+ if (did_emsg > did_emsg_before)
+ return;
if (argvars[2].v_type != VAR_UNKNOWN)
last = tv_get_lnum_buf(&argvars[2], buf);
else
***************
*** 525,534 ****
if (buf->b_ml.ml_mfp == NULL || first < 1
|| first > buf->b_ml.ml_line_count || last < first)
- {
- rettv->vval.v_number = 1; // FAIL
return;
- }
if (!is_curbuf)
{
--- 531,537 ----
***************
*** 577,582 ****
--- 580,586 ----
curbuf = curbuf_save;
curwin = curwin_save;
}
+ rettv->vval.v_number = 0; // OK
}
/*
***************
*** 780,785 ****
--- 784,790 ----
linenr_T lnum = 1;
linenr_T end = 1;
buf_T *buf;
+ int did_emsg_before = did_emsg;
if (in_vim9script()
&& (check_for_buffer_arg(argvars, 0) == FAIL
***************
*** 791,796 ****
--- 796,803 ----
if (buf != NULL)
{
lnum = tv_get_lnum_buf(&argvars[1], buf);
+ if (did_emsg > did_emsg_before)
+ return;
if (argvars[2].v_type == VAR_UNKNOWN)
end = lnum;
else
***************
*** 852,863 ****
f_setline(typval_T *argvars, typval_T *rettv)
{
linenr_T lnum;
if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL)
return;
lnum = tv_get_lnum(&argvars[0]);
! set_buffer_lines(curbuf, lnum, FALSE, &argvars[1], rettv);
}
#endif // FEAT_EVAL
--- 859,872 ----
f_setline(typval_T *argvars, typval_T *rettv)
{
linenr_T lnum;
+ int did_emsg_before = did_emsg;
if (in_vim9script() && check_for_lnum_arg(argvars, 0) == FAIL)
return;
lnum = tv_get_lnum(&argvars[0]);
! if (did_emsg == did_emsg_before)
! set_buffer_lines(curbuf, lnum, FALSE, &argvars[1], rettv);
}
#endif // FEAT_EVAL
*** ../vim-8.2.3918/src/typval.c 2021-12-25 19:29:18.409881900 +0000
--- src/typval.c 2021-12-28 11:08:20.194285430 +0000
***************
*** 2249,2257 ****
if (lnum <= 0 && argvars[0].v_type != VAR_NUMBER)
{
int fnum;
! pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum, FALSE);
// no valid number, try using arg like line()
if (fp != NULL)
lnum = fp->lnum;
}
--- 2249,2258 ----
if (lnum <= 0 && argvars[0].v_type != VAR_NUMBER)
{
int fnum;
! pos_T *fp;
// no valid number, try using arg like line()
+ fp = var2fpos(&argvars[0], TRUE, &fnum, FALSE);
if (fp != NULL)
lnum = fp->lnum;
}
***************
*** 2269,2274 ****
--- 2270,2276 ----
if (argvars[0].v_type == VAR_STRING
&& argvars[0].vval.v_string != NULL
&& argvars[0].vval.v_string[0] == '$'
+ && argvars[0].vval.v_string[1] == NUL
&& buf != NULL)
return buf->b_ml.ml_line_count;
return (linenr_T)tv_get_number_chk(&argvars[0], NULL);
*** ../vim-8.2.3918/src/testdir/test_vim9_builtin.vim 2021-12-27
20:57:03.487387908 +0000
--- src/testdir/test_vim9_builtin.vim 2021-12-28 11:23:03.889197420 +0000
***************
*** 183,189 ****
CheckDefAndScriptFailure(['append([1], "x")'], ['E1013: Argument 1: type
mismatch, expected string but got list<number>', 'E1220: String or Number
required for argument 1'])
CheckDefExecAndScriptFailure(['append("", "x")'], 'E1209: Invalid value for
a line number')
CheckDefExecAndScriptFailure(['append(".a", "x")'], 'E1209: Invalid value
for a line number')
! CheckDefExecAndScriptFailure(['append("''aa", "x")'], 'E1209: Invalid value
for a line number')
CheckDefExecAndScriptFailure(['append(-1, "x")'], 'E966: Invalid line
number: -1')
bwipe!
enddef
--- 183,190 ----
CheckDefAndScriptFailure(['append([1], "x")'], ['E1013: Argument 1: type
mismatch, expected string but got list<number>', 'E1220: String or Number
required for argument 1'])
CheckDefExecAndScriptFailure(['append("", "x")'], 'E1209: Invalid value for
a line number')
CheckDefExecAndScriptFailure(['append(".a", "x")'], 'E1209: Invalid value
for a line number')
! # only get one error
! assert_fails('append("''aa", "x")', ['E1209: Invalid value for a line
number: "''aa"', 'E1209:'])
CheckDefExecAndScriptFailure(['append(-1, "x")'], 'E966: Invalid line
number: -1')
bwipe!
enddef
***************
*** 203,208 ****
--- 204,211 ----
CheckDefAndScriptFailure(['appendbufline([1], 1, "x")'], ['E1013: Argument
1: type mismatch, expected string but got list<number>', 'E1220: String or
Number required for argument 1'])
CheckDefAndScriptFailure(['appendbufline(1, [1], "x")'], ['E1013: Argument
2: type mismatch, expected string but got list<number>', 'E1220: String or
Number required for argument 2'])
CheckDefExecAndScriptFailure(['appendbufline(' .. bnum .. ', -1, "x")'],
'E966: Invalid line number: -1')
+ CheckDefExecAndScriptFailure(['appendbufline(' .. bnum .. ', "$a", "x")'],
'E1030: Using a String as a Number: "$a"')
+ assert_fails('appendbufline(' .. bnum .. ', "$a", "x")', ['E1030: Using a
String as a Number: "$a"', 'E1030:'])
CheckDefAndScriptFailure(['appendbufline(1, 1, {"a": 10})'], ['E1013:
Argument 3: type mismatch, expected string but got dict<number>', 'E1224:
String, Number or List required for argument 3'])
bnum->bufwinid()->win_gotoid()
appendbufline('', 0, 'numbers')
***************
*** 768,773 ****
--- 771,780 ----
setline(1, ['one', 'two'])
deletebufline('', 1)
getline(1, '$')->assert_equal(['two'])
+
+ assert_fails('deletebufline("", "$a", "$b")', ['E1030: Using a String as a
Number: "$a"', 'E1030: Using a String as a Number: "$a"'])
+ assert_fails('deletebufline("", "$", "$b")', ['E1030: Using a String as a
Number: "$b"', 'E1030: Using a String as a Number: "$b"'])
+
bwipe!
enddef
***************
*** 1459,1465 ****
--- 1466,1475 ----
getbufline(-1, '$', '$')->assert_equal([])
getbufline(-1, 1, '$')->assert_equal([])
+ assert_fails('getbufline("", "$a", "$b")', ['E1030: Using a String as a
Number: "$a"', 'E1030: Using a String as a Number: "$a"'])
+ assert_fails('getbufline("", "$", "$b")', ['E1030: Using a String as a
Number: "$b"', 'E1030: Using a String as a Number: "$b"'])
bwipe!
+
CheckDefAndScriptFailure(['getbufline([], 2)'], ['E1013: Argument 1: type
mismatch, expected string but got list<unknown>', 'E1220: String or Number
required for argument 1'])
CheckDefAndScriptFailure(['getbufline("a", [])'], ['E1013: Argument 2: type
mismatch, expected string but got list<unknown>', 'E1220: String or Number
required for argument 2'])
CheckDefAndScriptFailure(['getbufline("a", 2, 0z10)'], ['E1013: Argument 3:
type mismatch, expected string but got blob', 'E1220: String or Number required
for argument 3'])
***************
*** 3311,3316 ****
--- 3321,3327 ----
CheckDefAndScriptFailure(['setline([1], "x")'], ['E1013: Argument 1: type
mismatch, expected string but got list<number>', 'E1220: String or Number
required for argument 1'])
CheckDefExecAndScriptFailure(['setline("", "x")'], 'E1209: Invalid value
for a line number')
CheckDefExecAndScriptFailure(['setline(-1, "x")'], 'E966: Invalid line
number: -1')
+ assert_fails('setline(".a", "x")', ['E1209:', 'E1209:'])
bw!
enddef
*** ../vim-8.2.3918/src/version.c 2021-12-27 21:42:54.342905525 +0000
--- src/version.c 2021-12-28 11:23:58.533088294 +0000
***************
*** 751,752 ****
--- 751,754 ----
{ /* Add new patch number below this line */
+ /**/
+ 3919,
/**/
--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20211228112824.4F53C1C0A5B%40moolenaar.net.