Commit: patch 9.2.1000: Vim9: listener_add() fails when given only a callback

4 views
Skip to first unread message

Christian Brabandt

unread,
Aug 23, 2026, 4:00:13 PM (5 days ago) Aug 23
to vim...@googlegroups.com
patch 9.2.1000: Vim9: listener_add() fails when given only a callback

Commit: https://github.com/vim/vim/commit/937992b1438a341b8ab6b1cf67edcb01d94c133e
Author: Hirohito Higashi <h.eas...@gmail.com>
Date: Sun Aug 23 19:45:42 2026 +0000

patch 9.2.1000: Vim9: listener_add() fails when given only a callback

Problem: In Vim9 script, listener_add() given only a callback fails
with "E1212: Bool required for argument 3".
Solution: Check the third argument only when the second one is there.
Without a second argument the third is not filled in, so
what was checked was whatever happened to be in that slot
(Hirohito Higashi).

closes: #21116

Co-Authored-By: Claude Opus 5 (1M context) <nor...@anthropic.com>
Signed-off-by: Hirohito Higashi <h.eas...@gmail.com>
Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/change.c b/src/change.c
index 7edbd9b8d..f8c039305 100644
--- a/src/change.c
+++ b/src/change.c
@@ -403,7 +403,8 @@ f_listener_add(typval_T *argvars, typval_T *rettv)

if (in_vim9script() && (
check_for_opt_buffer_arg(argvars, 1) == FAIL
- || check_for_opt_bool_or_dict_arg(argvars, 2) == FAIL))
+ || (argvars[1].v_type != VAR_UNKNOWN
+ && check_for_opt_bool_or_dict_arg(argvars, 2) == FAIL)))
return;

callback = get_callback(&argvars[0]);
diff --git a/src/testdir/test_listener.vim b/src/testdir/test_listener.vim
index b981fd72d..7639f996d 100644
--- a/src/testdir/test_listener.vim
+++ b/src/testdir/test_listener.vim
@@ -2,6 +2,8 @@
" listener_add() and listener_remove()
" redraw_listener_add() and redraw_listener_remove()

+import './util/vim9.vim' as v9
+
func s:StoreList(s, e, a, l)
let s:start = a:s
let s:end = a:e
@@ -991,4 +993,26 @@ func Test_listener_add_in_sandbox()
call assert_fails('sandbox call listener_remove(1)', 'E48:')
endfunc

+" Using listener_add() with only the callback, from Vim9 script. The check on
+" the third argument used to look at it even when the second one was not there.
+func Test_listener_add_one_arg_vim9()
+ let lines =<< trim END
+ vim9script
+ var seen = 0
+ def Listen(bufnr: number, start: number, end: number, added: number,
+ changes: list<dict<any>>)
+ seen += 1
+ enddef
+ new
+ var id = listener_add(Listen)
+ assert_true(id > 0)
+ setline(1, 'x')
+ listener_flush()
+ assert_equal(1, seen)
+ listener_remove(id)
+ bwipe!
+ END
+ call v9.CheckScriptSuccess(lines)
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 5e5717f9a..92fdb20c6 100644
--- a/src/version.c
+++ b/src/version.c
@@ -763,6 +763,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1000,
/**/
999,
/**/
Reply all
Reply to author
Forward
0 new messages