]> granicus.if.org Git - vim/commitdiff
patch 8.2.3408: can delete a numbered function v8.2.3408
authorBram Moolenaar <Bram@vim.org>
Mon, 6 Sep 2021 18:56:56 +0000 (20:56 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 6 Sep 2021 18:56:56 +0000 (20:56 +0200)
Problem:    Can delete a numbered function. (Naohiro Ono)
Solution:   Disallow deleting a numbered function. (closes #8760)

src/testdir/test_user_func.vim
src/userfunc.c
src/version.c

index 747ec486bc714fc63814accf2a0ae5f28e354f5f..819a6bba90dce2e8ee89e29d70a0a3321d06af31 100644 (file)
@@ -434,6 +434,11 @@ func Test_del_func()
   func d.fn()
     return 1
   endfunc
+
+  " cannot delete the dict function by number
+  let nr = substitute(execute('echo d'), '.*function(''\(\d\+\)'').*', '\1', '')
+  call assert_fails('delfunction g:' .. nr, 'E475: Invalid argument: g:')
+
   delfunc d.fn
   call assert_equal({'a' : 10}, d)
 endfunc
index aa55bc85ead7fb6b9242b9dba2dcb9e3651110ba..e51df51ffd4a7f79860c32f82e83d4a5e9c12dc4 100644 (file)
@@ -4669,6 +4669,13 @@ ex_delfunction(exarg_T *eap)
     if (eap->nextcmd != NULL)
        *p = NUL;
 
+    if (isdigit(*name) && fudi.fd_dict == NULL)
+    {
+       if (!eap->skip)
+           semsg(_(e_invarg2), eap->arg);
+       vim_free(name);
+       return;
+    }
     if (!eap->skip)
        fp = find_func(name, is_global, NULL);
     vim_free(name);
index 6301d77a8e2c2cfb4b7a0fd44b718c4f01ae91a1..54533dc91e633000779c0c923bc5121ba5f4d15b 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3408,
 /**/
     3407,
 /**/