]> granicus.if.org Git - vim/commitdiff
patch 8.2.4145: confusing error when using name of import for a function v8.2.4145
authorBram Moolenaar <Bram@vim.org>
Wed, 19 Jan 2022 17:21:29 +0000 (17:21 +0000)
committerBram Moolenaar <Bram@vim.org>
Wed, 19 Jan 2022 17:21:29 +0000 (17:21 +0000)
Problem:    Confusing error when using name of import for a function.
Solution:   Pass a flag to trans_function_name().

src/eval.c
src/proto/userfunc.pro
src/testdir/test_vim9_import.vim
src/userfunc.c
src/version.c
src/vim.h

index 2b145e1a2a4f2ebc47a55bb2235d0b7455d8c873..9313c272077d3da6fffee847269c3d4597c7bf36 100644 (file)
@@ -2072,7 +2072,7 @@ eval_func(
     // If "s" is the name of a variable of type VAR_FUNC
     // use its contents.
     s = deref_func_name(s, &len, &partial,
-                       in_vim9script() ? &type : NULL, !evaluate, &found_var);
+                in_vim9script() ? &type : NULL, !evaluate, FALSE, &found_var);
 
     // Need to make a copy, in case evaluating the arguments makes
     // the name invalid.
index 416a33bed3cadedd17b2740d2d90b39668f7d499..475b70af4c5b12ea55aec5cdb1dfba13133ccbf1 100644 (file)
@@ -4,7 +4,7 @@ hashtab_T *func_tbl_get(void);
 char_u *get_lambda_name(void);
 char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state);
 int get_lambda_tv(char_u **arg, typval_T *rettv, int types_optional, evalarg_T *evalarg);
-char_u *deref_func_name(char_u *name, int *lenp, partial_T **partialp, type_T **type, int no_autoload, int *found_var);
+char_u *deref_func_name(char_u *name, int *lenp, partial_T **partialp, type_T **type, int no_autoload, int new_function, int *found_var);
 void emsg_funcname(char *ermsg, char_u *name);
 int get_func_tv(char_u *name, int len, typval_T *rettv, char_u **arg, evalarg_T *evalarg, funcexe_T *funcexe);
 char_u *fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error);
index 3f918f849eba1cf114a45c8917d68fc62136ba1e..49ff16508766e3d4c2f0aa3dcb6cccb957cbde8b 100644 (file)
@@ -457,6 +457,16 @@ def Test_import_fails()
   END
   CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself'])
 
+  lines =<< trim END
+      vim9script
+      import './Xthat.vim' as That
+      def Func()
+        echo That()
+      enddef
+      Func()
+  END
+  CheckScriptFailure(lines, 'E1236: Cannot use That itself')
+
   lines =<< trim END
       import './Xthat.vim' as one
       import './Xthat.vim' as two
@@ -1000,7 +1010,7 @@ def Test_func_overrules_import_fails()
       echo 'local to function'
     enddef
   END
-  CheckScriptFailure(lines, 'E1236:')
+  CheckScriptFailure(lines, 'E1213: Redefining imported item "Func"')
 
   lines =<< trim END
     vim9script
index e6c9ab06c28acbe1118bbe1ce26669a55619c3d9..7d3bb292d8f5748f1c75060843466a613962f93d 100644 (file)
@@ -1567,6 +1567,7 @@ errret:
  * "partialp".
  * If "type" is not NULL and a Vim9 script-local variable is found look up the
  * type of the variable.
+ * If "new_function" is TRUE the name is for a new function.
  * If "found_var" is not NULL and a variable was found set it to TRUE.
  */
     char_u *
@@ -1576,6 +1577,7 @@ deref_func_name(
        partial_T   **partialp,
        type_T      **type,
        int         no_autoload,
+       int         new_function,
        int         *found_var)
 {
     dictitem_T *v;
@@ -1614,7 +1616,10 @@ deref_func_name(
        if (import != NULL)
        {
            name[len] = NUL;
-           semsg(_(e_cannot_use_str_itself_it_is_imported), name);
+           if (new_function)
+               semsg(_(e_redefining_imported_item_str), name);
+           else
+               semsg(_(e_cannot_use_str_itself_it_is_imported), name);
            name[len] = cc;
            *lenp = 0;
            return (char_u *)"";        // just in case
@@ -3751,7 +3756,7 @@ trans_function_name(
     {
        len = (int)STRLEN(lv.ll_exp_name);
        name = deref_func_name(lv.ll_exp_name, &len, partial, type,
-                                               flags & TFN_NO_AUTOLOAD, NULL);
+                         flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL);
        if (name == lv.ll_exp_name)
            name = NULL;
     }
@@ -3783,7 +3788,7 @@ trans_function_name(
     {
        len = (int)(end - *pp);
        name = deref_func_name(*pp, &len, partial, type,
-                                               flags & TFN_NO_AUTOLOAD, NULL);
+                         flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL);
        if (name == *pp)
            name = NULL;
     }
@@ -4146,7 +4151,7 @@ define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free)
     else
     {
        name = save_function_name(&p, &is_global, eap->skip,
-                                                      TFN_NO_AUTOLOAD, &fudi);
+                                       TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi);
        paren = (vim_strchr(p, '(') != NULL);
        if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)
        {
@@ -5199,7 +5204,8 @@ ex_call(exarg_T *eap)
     // from trans_function_name().
     len = (int)STRLEN(tofree);
     name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial,
-           in_vim9script() && type == NULL ? &type : NULL, FALSE, &found_var);
+           in_vim9script() && type == NULL ? &type : NULL,
+                                                    FALSE, FALSE, &found_var);
 
     // Skip white space to allow ":call func ()".  Not good, but required for
     // backward compatibility.
index 86a727f8bda5fd2edbfa0508ec671c85c1ed40b4..1906fc4aaf912bd9f0fddad79e491f2d490c9ac1 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4145,
 /**/
     4144,
 /**/
index 05bafdc2c46defbb2bf7cc1731f03d6c20976418..cb8af5de23299775992b14c5b57b3096b25dce3d 100644 (file)
--- a/src/vim.h
+++ b/src/vim.h
@@ -2632,6 +2632,7 @@ typedef enum {
 #define TFN_READ_ONLY  0x10    // will not change the var
 #define TFN_NO_DECL    0x20    // only used for GLV_NO_DECL
 #define TFN_COMPILING  0x40    // only used for GLV_COMPILING
+#define TFN_NEW_FUNC   0x80    // defining a new function
 
 // Values for get_lval() flags argument:
 #define GLV_QUIET      TFN_QUIET       // no error messages