Mercurial > vim
diff src/testdir/test_vim9_func.vim @ 26470:ff0310e6f889 v8.2.3765
patch 8.2.3765: Vim9: cannot use a lambda for 'opfunc' and others
Commit: https://github.com/vim/vim/commit/dcb53be4418fe263a71c7738315241031df6c986
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Dec 9 14:23:43 2021 +0000
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 09 Dec 2021 15:30:04 +0100 |
parents | a926ccd92ae1 |
children | b115b552071f |
line wrap: on
line diff
--- a/src/testdir/test_vim9_func.vim +++ b/src/testdir/test_vim9_func.vim @@ -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