diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-01-19 17:21:29 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-01-19 17:21:29 +0000 |
commit | 937610bc9f9c827e3e25fed32661fcbf3f994e10 (patch) | |
tree | 1ce20686961b8b5e70edf33775ae14e1485b4eca /src | |
parent | 1a8825d7a3484d76ca16ea2aa9769cadca7758a4 (diff) |
patch 8.2.4145: confusing error when using name of import for a functionv8.2.4145
Problem: Confusing error when using name of import for a function.
Solution: Pass a flag to trans_function_name().
Diffstat (limited to 'src')
-rw-r--r-- | src/eval.c | 2 | ||||
-rw-r--r-- | src/proto/userfunc.pro | 2 | ||||
-rw-r--r-- | src/testdir/test_vim9_import.vim | 12 | ||||
-rw-r--r-- | src/userfunc.c | 16 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim.h | 1 |
6 files changed, 27 insertions, 8 deletions
diff --git a/src/eval.c b/src/eval.c index 2b145e1a2a..9313c27207 100644 --- a/src/eval.c +++ b/src/eval.c @@ -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. diff --git a/src/proto/userfunc.pro b/src/proto/userfunc.pro index 416a33bed3..475b70af4c 100644 --- a/src/proto/userfunc.pro +++ b/src/proto/userfunc.pro @@ -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); diff --git a/src/testdir/test_vim9_import.vim b/src/testdir/test_vim9_import.vim index 3f918f849e..49ff165087 100644 --- a/src/testdir/test_vim9_import.vim +++ b/src/testdir/test_vim9_import.vim @@ -458,6 +458,16 @@ def Test_import_fails() 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 END @@ -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 diff --git a/src/userfunc.c b/src/userfunc.c index e6c9ab06c2..7d3bb292d8 100644 --- a/src/userfunc.c +++ b/src/userfunc.c @@ -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. diff --git a/src/version.c b/src/version.c index 86a727f8bd..1906fc4aaf 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4145, +/**/ 4144, /**/ 4143, @@ -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 |