summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/builtin.txt7
-rw-r--r--src/evalbuffer.c27
-rw-r--r--src/testdir/test_vim9_builtin.vim13
-rw-r--r--src/typval.c4
-rw-r--r--src/version.c2
5 files changed, 39 insertions, 14 deletions
diff --git a/runtime/doc/builtin.txt b/runtime/doc/builtin.txt
index 8855dd0a35..cf48b4d989 100644
--- a/runtime/doc/builtin.txt
+++ b/runtime/doc/builtin.txt
@@ -806,9 +806,10 @@ appendbufline({buf}, {lnum}, {text}) *appendbufline()*
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.
+ {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}.
diff --git a/src/evalbuffer.c b/src/evalbuffer.c
index 50d26c4b17..37febe4059 100644
--- a/src/evalbuffer.c
+++ b/src/evalbuffer.c
@@ -274,12 +274,14 @@ done:
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]);
- set_buffer_lines(curbuf, lnum, TRUE, &argvars[1], rettv);
+ if (did_emsg == did_emsg_before)
+ set_buffer_lines(curbuf, lnum, TRUE, &argvars[1], rettv);
}
/*
@@ -290,6 +292,7 @@ buf_set_append_line(typval_T *argvars, typval_T *rettv, int append)
{
linenr_T lnum;
buf_T *buf;
+ int did_emsg_before = did_emsg;
if (in_vim9script()
&& (check_for_buffer_arg(argvars, 0) == FAIL
@@ -303,7 +306,8 @@ buf_set_append_line(typval_T *argvars, typval_T *rettv, int append)
else
{
lnum = tv_get_lnum_buf(&argvars[1], buf);
- set_buffer_lines(buf, lnum, append, &argvars[2], rettv);
+ if (did_emsg == did_emsg_before)
+ set_buffer_lines(buf, lnum, append, &argvars[2], rettv);
}
}
@@ -502,6 +506,9 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
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,13 +518,12 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
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 (did_emsg > did_emsg_before)
+ return;
if (argvars[2].v_type != VAR_UNKNOWN)
last = tv_get_lnum_buf(&argvars[2], buf);
else
@@ -525,10 +531,7 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
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)
{
@@ -577,6 +580,7 @@ f_deletebufline(typval_T *argvars, typval_T *rettv)
curbuf = curbuf_save;
curwin = curwin_save;
}
+ rettv->vval.v_number = 0; // OK
}
/*
@@ -780,6 +784,7 @@ f_getbufline(typval_T *argvars, typval_T *rettv)
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,6 +796,8 @@ f_getbufline(typval_T *argvars, typval_T *rettv)
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,12 +859,14 @@ f_setbufline(typval_T *argvars, typval_T *rettv)
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]);
- set_buffer_lines(curbuf, lnum, FALSE, &argvars[1], rettv);
+ if (did_emsg == did_emsg_before)
+ set_buffer_lines(curbuf, lnum, FALSE, &argvars[1], rettv);
}
#endif // FEAT_EVAL
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index d528b71a65..978ceb0685 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -183,7 +183,8 @@ def Test_append()
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')
+ # 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,6 +204,8 @@ def Test_appendbufline()
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,6 +771,10 @@ def Test_deletebufline()
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,7 +1466,10 @@ def Test_getbufline()
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,6 +3321,7 @@ def Test_setline()
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
diff --git a/src/typval.c b/src/typval.c
index 2f773b602e..34ff47c0a6 100644
--- a/src/typval.c
+++ b/src/typval.c
@@ -2249,9 +2249,10 @@ tv_get_lnum(typval_T *argvars)
if (lnum <= 0 && argvars[0].v_type != VAR_NUMBER)
{
int fnum;
- pos_T *fp = var2fpos(&argvars[0], TRUE, &fnum, FALSE);
+ 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,6 +2270,7 @@ tv_get_lnum_buf(typval_T *argvars, buf_T *buf)
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);
diff --git a/src/version.c b/src/version.c
index 4e6c07b9fb..2045de932d 100644
--- a/src/version.c
+++ b/src/version.c
@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3919,
+/**/
3918,
/**/
3917,