Patch 8.2.3793
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)
Files:      src/evalvars.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.3792/src/evalvars.c      2021-12-12 16:26:35.864627610 +0000
--- src/evalvars.c      2021-12-12 21:00:52.013246907 +0000
***************
*** 1414,1420 ****
                n = (long)tv_get_number(tv);
        }
  
!       if (opt_p_flags & P_FUNC && (tv->v_type == VAR_PARTIAL
                                                || tv->v_type == VAR_FUNC))
        {
            // If the option can be set to a function reference or a lambda
--- 1414,1420 ----
                n = (long)tv_get_number(tv);
        }
  
!       if ((opt_p_flags & P_FUNC) && (tv->v_type == VAR_PARTIAL
                                                || tv->v_type == VAR_FUNC))
        {
            // If the option can be set to a function reference or a lambda
***************
*** 2723,2729 ****
                if (rettv != NULL)
                {
                    rettv->v_type = VAR_FUNC;
!                   rettv->vval.v_string = vim_strsave(ufunc->uf_name);
                    if (rettv->vval.v_string != NULL)
                        func_ref(ufunc->uf_name);
                }
--- 2723,2734 ----
                if (rettv != NULL)
                {
                    rettv->v_type = VAR_FUNC;
!                   if (STRNCMP(name, "g:", 2) == 0)
!                       // Keep the "g:", otherwise script-local may be
!                       // assumed.
!                       rettv->vval.v_string = vim_strsave(name);
!                   else
!                       rettv->vval.v_string = vim_strsave(ufunc->uf_name);
                    if (rettv->vval.v_string != NULL)
                        func_ref(ufunc->uf_name);
                }
*** ../vim-8.2.3792/src/testdir/test_vim9_func.vim      2021-12-11 
16:13:32.231721218 +0000
--- src/testdir/test_vim9_func.vim      2021-12-12 21:00:06.053206248 +0000
***************
*** 1224,1229 ****
--- 1224,1248 ----
    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.
*** ../vim-8.2.3792/src/version.c       2021-12-12 20:07:58.724337327 +0000
--- src/version.c       2021-12-12 21:00:17.249216652 +0000
***************
*** 755,756 ****
--- 755,758 ----
  {   /* Add new patch number below this line */
+ /**/
+     3793,
  /**/

-- 
I am also told that there is a logical proof out there somewhere
that demonstrates that there is no task which duct tape cannot handle.
                                        -- Paul Brannan

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20211212210238.5C8F01C0D69%40moolenaar.net.

Raspunde prin e-mail lui