To: vim_dev@googlegroups.com Subject: Patch 8.2.3826 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3826 Problem: Vim9: using "g:Func" as a funcref does not work in a :def function. Solution: Include "g:" in the function name. (closes #9336) Files: src/vim9compile.c, src/testdir/test_vim9_func.vim, src/testdir/test_vim9_disassemble.vim *** ../vim-8.2.3825/src/vim9compile.c 2021-12-10 16:55:53.515240212 +0000 --- src/vim9compile.c 2021-12-16 15:04:00.267604591 +0000 *************** *** 1281,1292 **** generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type) { isn_T *isn; RETURN_OK_IF_SKIP(cctx); if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL) return FAIL; ! isn->isn_arg.string = name == NULL ? NULL : vim_strsave(name); return OK; } --- 1281,1306 ---- generate_PUSHFUNC(cctx_T *cctx, char_u *name, type_T *type) { isn_T *isn; + char_u *funcname; RETURN_OK_IF_SKIP(cctx); if ((isn = generate_instr_type(cctx, ISN_PUSHFUNC, type)) == NULL) return FAIL; ! if (name == NULL) ! funcname = NULL; ! else if (*name == K_SPECIAL) // script-local ! funcname = vim_strsave(name); ! else ! { ! funcname = alloc(STRLEN(name) + 3); ! if (funcname != NULL) ! { ! STRCPY(funcname, "g:"); ! STRCPY(funcname + 2, name); ! } ! } + isn->isn_arg.string = funcname; return OK; } *** ../vim-8.2.3825/src/testdir/test_vim9_func.vim 2021-12-14 20:26:49.658164887 +0000 --- src/testdir/test_vim9_func.vim 2021-12-16 15:01:28.023863235 +0000 *************** *** 1232,1242 **** --- 1232,1254 ---- g:result = getreg('"')->count(' ') return '' enddef + # global function works at script level &operatorfunc = g:CountSpaces new 'a b c d e'->setline(1) feedkeys("g@_", 'x') assert_equal(4, g:result) + + &operatorfunc = '' + g:result = 0 + # global function works in :def function + def Func() + &operatorfunc = g:CountSpaces + enddef + Func() + feedkeys("g@_", 'x') + assert_equal(4, g:result) + bwipe! END CheckScriptSuccess(lines) *** ../vim-8.2.3825/src/testdir/test_vim9_disassemble.vim 2021-12-09 14:23:40.265634965 +0000 --- src/testdir/test_vim9_disassemble.vim 2021-12-16 15:46:59.142187628 +0000 *************** *** 2413,2419 **** assert_match('\d*_UseMember\_s*' .. 'var d = {func: Legacy}\_s*' .. '\d PUSHS "func"\_s*' .. ! '\d PUSHFUNC "Legacy"\_s*' .. '\d NEWDICT size 1\_s*' .. '\d STORE $0\_s*' .. --- 2413,2419 ---- assert_match('\d*_UseMember\_s*' .. 'var d = {func: Legacy}\_s*' .. '\d PUSHS "func"\_s*' .. ! '\d PUSHFUNC "g:Legacy"\_s*' .. '\d NEWDICT size 1\_s*' .. '\d STORE $0\_s*' .. *** ../vim-8.2.3825/src/version.c 2021-12-16 14:45:09.365563190 +0000 --- src/version.c 2021-12-16 14:59:36.300053562 +0000 *************** *** 751,752 **** --- 751,754 ---- { /* Add new patch number below this line */ + /**/ + 3826, /**/ -- Microsoft is to software what McDonalds is to gourmet cooking /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///