1
0
forked from aniani/vim

patch 8.2.3793: using "g:Func" as a funcref does not work in script context

Problem:    Using "g:Func" as a funcref does not work in script context
            because "g:" is dropped.
Solution:   Keep "g:" in the name.  Also add parenthesis to avoid confusing
            operator prececence. (closes #9336)
This commit is contained in:
Bram Moolenaar
2021-12-12 21:02:03 +00:00
parent 04ef1fb13d
commit ef082e12df
3 changed files with 28 additions and 2 deletions

View File

@@ -1224,6 +1224,25 @@ def Test_set_opfunc_to_lambda()
CheckScriptSuccess(lines)
enddef
def Test_set_opfunc_to_global_function()
var lines =<< trim END
vim9script
def g:CountSpaces(type = ''): string
normal! '[V']y
g:result = getreg('"')->count(' ')
return ''
enddef
&operatorfunc = g:CountSpaces
new
'a b c d e'->setline(1)
feedkeys("g@_", 'x')
assert_equal(4, g:result)
bwipe!
END
CheckScriptSuccess(lines)
&operatorfunc = ''
enddef
def Test_lambda_type_allocated()
# Check that unreferencing a partial using a lambda can use the variable type
# after the lambda has been freed and does not leak memory.