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_disassemble.vim b/src/testdir/test_vim9_disassemble.vim
index 184f557..4cf37b7 100644
--- a/src/testdir/test_vim9_disassemble.vim
+++ b/src/testdir/test_vim9_disassemble.vim
@@ -316,6 +316,7 @@
w:windowvar = 'wv'
t:tabpagevar = 'tv'
&tabstop = 8
+ &opfunc = (t) => len(t)
$ENVVAR = 'ev'
@z = 'rv'
enddef
@@ -343,12 +344,17 @@
' STOREW w:windowvar.*' ..
't:tabpagevar = ''tv''.*' ..
' STORET t:tabpagevar.*' ..
- '&tabstop = 8.*' ..
- ' STOREOPT &tabstop.*' ..
- '$ENVVAR = ''ev''.*' ..
- ' STOREENV $ENVVAR.*' ..
+ '&tabstop = 8\_s*' ..
+ '\d\+ PUSHNR 8\_s*' ..
+ '\d\+ STOREOPT &tabstop\_s*' ..
+ '&opfunc = (t) => len(t)\_s*' ..
+ '\d\+ FUNCREF <lambda>\d\+\_s*' ..
+ '\d\+ STOREFUNCOPT &opfunc\_s*' ..
+ '$ENVVAR = ''ev''\_s*' ..
+ '\d\+ PUSHS "ev"\_s*' ..
+ '\d\+ STOREENV $ENVVAR\_s*' ..
'@z = ''rv''.*' ..
- ' STOREREG @z.*',
+ '\d\+ STOREREG @z.*',
res)
enddef
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