1
0
forked from aniani/vim

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.
This commit is contained in:
Bram Moolenaar
2021-12-09 14:23:43 +00:00
parent d0fb907253
commit dcb53be441
6 changed files with 90 additions and 19 deletions

View File

@@ -1202,6 +1202,28 @@ def Test_lambda_in_reduce_line_break()
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