Patch 8.2.1290

4 views
Skip to first unread message

Bram Moolenaar

unread,
Jul 25, 2020, 9:41:48 AM7/25/20
to vim...@googlegroups.com

Patch 8.2.1290
Problem: Vim9: cannot replace a global function.
Solution: Allow for "!" on a global function. (closes #6524) Also fix that
:delfunc on a :def function only made it empty.
Files: src/userfunc.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.1289/src/userfunc.c 2020-07-23 17:16:15.050100601 +0200
--- src/userfunc.c 2020-07-25 15:35:28.793642878 +0200
***************
*** 1148,1153 ****
--- 1148,1155 ----
func_clear(fp, force);
if (force || fp->uf_dfunc_idx == 0)
func_free(fp, force);
+ else
+ fp->uf_flags |= FC_DEAD;
}


***************
*** 2557,2568 ****
char_u *heredoc_trimmed = NULL;
int vim9script = in_vim9script();

- if (vim9script && eap->forceit)
- {
- emsg(_(e_nobang));
- return NULL;
- }
-
/*
* ":function" without argument: list functions.
*/
--- 2559,2564 ----
***************
*** 2732,2737 ****
--- 2728,2740 ----
}
p = skipwhite(p + 1);

+ // In Vim9 script only global functions can be redefined.
+ if (vim9script && eap->forceit && !is_global)
+ {
+ emsg(_(e_nobang));
+ goto ret_free;
+ }
+
ga_init2(&newlines, (int)sizeof(char_u *), 3);

if (!eap->skip && name_arg == NULL)
*** ../vim-8.2.1289/src/testdir/test_vim9_script.vim 2020-07-23 22:41:39.779937421 +0200
--- src/testdir/test_vim9_script.vim 2020-07-25 15:39:45.260875958 +0200
***************
*** 468,473 ****
--- 468,521 ----
'enddef',
'DoThat()',
], 'E1084:')
+
+ # Check that global :def function can be replaced and deleted
+ let lines =<< trim END
+ vim9script
+ def g:Global(): string
+ return "yes"
+ enddef
+ assert_equal("yes", g:Global())
+ def! g:Global(): string
+ return "no"
+ enddef
+ assert_equal("no", g:Global())
+ delfunc g:Global
+ assert_false(exists('*g:Global'))
+ END
+ CheckScriptSuccess(lines)
+
+ # Check that global function can be replaced by a :def function and deleted
+ lines =<< trim END
+ vim9script
+ func g:Global()
+ return "yes"
+ endfunc
+ assert_equal("yes", g:Global())
+ def! g:Global(): string
+ return "no"
+ enddef
+ assert_equal("no", g:Global())
+ delfunc g:Global
+ assert_false(exists('*g:Global'))
+ END
+ CheckScriptSuccess(lines)
+
+ # Check that global :def function can be replaced by a function and deleted
+ lines =<< trim END
+ vim9script
+ def g:Global(): string
+ return "yes"
+ enddef
+ assert_equal("yes", g:Global())
+ func! g:Global()
+ return "no"
+ endfunc
+ assert_equal("no", g:Global())
+ delfunc g:Global
+ assert_false(exists('*g:Global'))
+ END
+ CheckScriptSuccess(lines)
enddef

func Test_wrong_type()
*** ../vim-8.2.1289/src/version.c 2020-07-25 14:11:50.545128202 +0200
--- src/version.c 2020-07-25 15:19:44.440403795 +0200
***************
*** 756,757 ****
--- 756,759 ----
{ /* Add new patch number below this line */
+ /**/
+ 1290,
/**/

--
hundred-and-one symptoms of being an internet addict:
83. Batteries in the TV remote now last for months.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages