patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Problem: Vim9: cannot use a lambda for 'opfunc' and others.
Solution: Convert the lambda to a string.
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 651da05..40affb3 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1202,6 +1202,28 @@
CheckScriptSuccess(lines)
enddef
+def Test_set_opfunc_to_lambda()
+ var lines =<< trim END
+ vim9script
+ nnoremap <expr> <F4> <SID>CountSpaces() .. '_'
+ def CountSpaces(type = ''): string
+ if type == ''
+ &operatorfunc = (t) => CountSpaces(t)
+ return 'g@'
+ endif
+ normal! '[V']y
+ g:result = getreg('"')->count(' ')
+ return ''
+ enddef
+ new
+ 'a b c d e'->setline(1)
+ feedkeys("\<F4>", 'x')
+ assert_equal(4, g:result)
+ bwipe!
+ END
+ CheckScriptSuccess(lines)
+enddef
+
" Default arg and varargs
def MyDefVarargs(one: string, two = 'foo', ...rest: list<string>): string
var res = one .. ',' .. two