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)
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 2c871d3..6d098ff 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -1224,6 +1224,25 @@
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.