vim-patch:8.2.1888: Vim9: getbufline(-1, 1, '$') gives an error

Problem:    Vim9: Getbufline(-1, 1, '$') gives an error.
Solution:   Return an empty list. (closes vim/vim#7180)

e6e70a10f1

Co-authored-by: Bram Moolenaar <Bram@vim.org>
This commit is contained in:
Jan Edmund Lazo
2026-06-21 20:27:50 -04:00
parent 2dd5e3eb4f
commit 264631c4c1
2 changed files with 14 additions and 6 deletions

View File

@@ -714,15 +714,19 @@ static void get_buffer_lines(buf_T *buf, linenr_T start, linenr_T end, bool retl
/// false: "getbufoneline()" function
static void getbufline(typval_T *argvars, typval_T *rettv, bool retlist)
{
linenr_T lnum = 1;
linenr_T end = 1;
const int did_emsg_before = did_emsg;
buf_T *const buf = tv_get_buf_from_arg(&argvars[0]);
const linenr_T lnum = tv_get_lnum_buf(&argvars[1], buf);
if (did_emsg > did_emsg_before) {
return;
if (buf != NULL) {
lnum = tv_get_lnum_buf(&argvars[1], buf);
if (did_emsg > did_emsg_before) {
return;
}
end = (argvars[2].v_type == VAR_UNKNOWN
? lnum
: tv_get_lnum_buf(&argvars[2], buf));
}
const linenr_T end = (argvars[2].v_type == VAR_UNKNOWN
? lnum
: tv_get_lnum_buf(&argvars[2], buf));
get_buffer_lines(buf, lnum, end, retlist, rettv);
}

View File

@@ -191,11 +191,15 @@ describe('getbufline() function', function()
end)
it('returns empty list when range is invalid', function()
eq({}, fn.getbufline(1, 0))
eq({}, fn.getbufline(-1, 1, '$'))
eq({}, fn.getbufline(-1, '$', '$'))
api.nvim_buf_set_lines(0, 0, 1, false, { 'foo', 'bar', 'baz' })
eq({}, fn.getbufline(1, 2, 1))
eq({}, fn.getbufline(1, -10, -20))
eq({}, fn.getbufline(1, -2, -1))
eq({}, fn.getbufline(1, -1, 9999))
eq({}, fn.getbufline(-1, 1, '$'))
eq({}, fn.getbufline(-1, '$', '$'))
end)
it('returns expected lines', function()
api.nvim_set_option_value('hidden', true, {})