]> granicus.if.org Git - vim/commitdiff
patch 8.2.4578: no warning when autoload script for completion has an error v8.2.4578
authorBram Moolenaar <Bram@vim.org>
Wed, 16 Mar 2022 13:09:15 +0000 (13:09 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 16 Mar 2022 13:09:15 +0000 (13:09 +0000)
Problem:    No warning when an autoload script for completion function has an
            error.
Solution:   Do not ignore errors when a function name is given with a dot or
            '#' character. (closes #9958)

src/eval.c
src/testdir/test_cmdline.vim
src/version.c

index b55ae1a20c3a8c11143dd9440d3b5adf18413540..62266f884b2a4f6fa3ff6b029a90d902f85f1fec 100644 (file)
@@ -695,6 +695,7 @@ call_vim_function(
     char_u     *arg;
     char_u     *name;
     char_u     *tofree = NULL;
+    int                ignore_errors;
 
     rettv->v_type = VAR_UNKNOWN;               // clear_tv() uses this
     CLEAR_FIELD(funcexe);
@@ -702,11 +703,18 @@ call_vim_function(
     funcexe.fe_lastline = curwin->w_cursor.lnum;
     funcexe.fe_evaluate = TRUE;
 
-    // The name might be "import.Func" or "Funcref".
+    // The name might be "import.Func" or "Funcref".  We don't know, we need to
+    // ignore errors for an undefined name.  But we do want errors when an
+    // autoload script has errors.  Guess that when there is a dot or '#' in
+    // the name showing errors is the right choice.
+    ignore_errors = vim_strchr(func, '.') == NULL
+                                   && vim_strchr(func, AUTOLOAD_CHAR) == NULL;
     arg = func;
-    ++emsg_off;
+    if (ignore_errors)
+       ++emsg_off;
     name = deref_function_name(&arg, &tofree, &EVALARG_EVALUATE, FALSE);
-    --emsg_off;
+    if (ignore_errors)
+       --emsg_off;
     if (name == NULL)
        name = func;
 
index bdcecbfa20e1073aff1b168efade85d2743ea177..20f932b308c2d2f260b61361673191dfb5cef767 100644 (file)
@@ -4,6 +4,7 @@ source check.vim
 source screendump.vim
 source view_util.vim
 source shared.vim
+import './vim9.vim' as v9
 
 func SetUp()
   func SaveLastScreenLine()
@@ -543,6 +544,32 @@ func Test_getcompletion()
   call assert_fails('call getcompletion("abc", [])', 'E475:')
 endfunc
 
+func Test_complete_autoload_error()
+  let save_rtp = &rtp
+  let lines =<< trim END
+      vim9script
+      export def Complete(..._): string
+        return 'match'
+      enddef
+      echo this will cause an error
+  END
+  call mkdir('Xdir/autoload', 'p')
+  call writefile(lines, 'Xdir/autoload/script.vim')
+  exe 'set rtp+=' .. getcwd() .. '/Xdir'
+
+  let lines =<< trim END
+      vim9script
+      import autoload 'script.vim'
+      command -nargs=* -complete=custom,script.Complete Cmd eval 0 + 0
+      &wildcharm = char2nr("\<Tab>")
+      feedkeys(":Cmd \<Tab>", 'xt')
+  END
+  call v9.CheckScriptFailure(lines, 'E121: Undefined variable: this')
+
+  let &rtp = save_rtp
+  call delete('Xdir', 'rf')
+endfunc
+
 func Test_fullcommand()
   let tests = {
         \ '':           '',
@@ -2671,8 +2698,7 @@ func Test_fuzzy_completion_userdefined_snr_func()
   endfunc
   set wildoptions=fuzzy
   call feedkeys(":call sendmail\<C-A>\<C-B>\"\<CR>", 'tx')
-  call assert_equal('"call SendSomemail() S1e2n3dmail() '
-        \ .. expand("<SID>") .. 'Sendmail()', @:)
+  call assert_match('"call SendSomemail() S1e2n3dmail() <SNR>\d\+_Sendmail()', @:)
   set wildoptions&
   delfunc s:Sendmail
   delfunc SendSomemail
index ba0058b679b2ea3bcba3c955792db897142b87cf..4c6920fbf5c47876f970d9e6e444c13825c541be 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4578,
 /**/
     4577,
 /**/