• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Révision73232ed49cf2dcd895ba918c2f31efd0a36f3760 (tree)
l'heure2022-01-20 02:30:05
AuteurBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Message de Log

patch 8.2.4145: confusing error when using name of import for a function

Commit: https://github.com/vim/vim/commit/937610bc9f9c827e3e25fed32661fcbf3f994e10
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jan 19 17:21:29 2022 +0000

patch 8.2.4145: confusing error when using name of import for a function
Problem: Confusing error when using name of import for a function.
Solution: Pass a flag to trans_function_name().

Change Summary

Modification

diff -r d0ce0a7ce04c -r 73232ed49cf2 src/eval.c
--- a/src/eval.c Wed Jan 19 14:45:05 2022 +0100
+++ b/src/eval.c Wed Jan 19 18:30:05 2022 +0100
@@ -2072,7 +2072,7 @@
20722072 // If "s" is the name of a variable of type VAR_FUNC
20732073 // use its contents.
20742074 s = deref_func_name(s, &len, &partial,
2075- in_vim9script() ? &type : NULL, !evaluate, &found_var);
2075+ in_vim9script() ? &type : NULL, !evaluate, FALSE, &found_var);
20762076
20772077 // Need to make a copy, in case evaluating the arguments makes
20782078 // the name invalid.
diff -r d0ce0a7ce04c -r 73232ed49cf2 src/proto/userfunc.pro
--- a/src/proto/userfunc.pro Wed Jan 19 14:45:05 2022 +0100
+++ b/src/proto/userfunc.pro Wed Jan 19 18:30:05 2022 +0100
@@ -4,7 +4,7 @@
44 char_u *get_lambda_name(void);
55 char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state);
66 int get_lambda_tv(char_u **arg, typval_T *rettv, int types_optional, evalarg_T *evalarg);
7-char_u *deref_func_name(char_u *name, int *lenp, partial_T **partialp, type_T **type, int no_autoload, int *found_var);
7+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);
88 void emsg_funcname(char *ermsg, char_u *name);
99 int get_func_tv(char_u *name, int len, typval_T *rettv, char_u **arg, evalarg_T *evalarg, funcexe_T *funcexe);
1010 char_u *fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error);
diff -r d0ce0a7ce04c -r 73232ed49cf2 src/testdir/test_vim9_import.vim
--- a/src/testdir/test_vim9_import.vim Wed Jan 19 14:45:05 2022 +0100
+++ b/src/testdir/test_vim9_import.vim Wed Jan 19 18:30:05 2022 +0100
@@ -458,6 +458,16 @@
458458 CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself'])
459459
460460 lines =<< trim END
461+ vim9script
462+ import './Xthat.vim' as That
463+ def Func()
464+ echo That()
465+ enddef
466+ Func()
467+ END
468+ CheckScriptFailure(lines, 'E1236: Cannot use That itself')
469+
470+ lines =<< trim END
461471 import './Xthat.vim' as one
462472 import './Xthat.vim' as two
463473 END
@@ -1000,7 +1010,7 @@
10001010 echo 'local to function'
10011011 enddef
10021012 END
1003- CheckScriptFailure(lines, 'E1236:')
1013+ CheckScriptFailure(lines, 'E1213: Redefining imported item "Func"')
10041014
10051015 lines =<< trim END
10061016 vim9script
diff -r d0ce0a7ce04c -r 73232ed49cf2 src/userfunc.c
--- a/src/userfunc.c Wed Jan 19 14:45:05 2022 +0100
+++ b/src/userfunc.c Wed Jan 19 18:30:05 2022 +0100
@@ -1567,6 +1567,7 @@
15671567 * "partialp".
15681568 * If "type" is not NULL and a Vim9 script-local variable is found look up the
15691569 * type of the variable.
1570+ * If "new_function" is TRUE the name is for a new function.
15701571 * If "found_var" is not NULL and a variable was found set it to TRUE.
15711572 */
15721573 char_u *
@@ -1576,6 +1577,7 @@
15761577 partial_T **partialp,
15771578 type_T **type,
15781579 int no_autoload,
1580+ int new_function,
15791581 int *found_var)
15801582 {
15811583 dictitem_T *v;
@@ -1614,7 +1616,10 @@
16141616 if (import != NULL)
16151617 {
16161618 name[len] = NUL;
1617- semsg(_(e_cannot_use_str_itself_it_is_imported), name);
1619+ if (new_function)
1620+ semsg(_(e_redefining_imported_item_str), name);
1621+ else
1622+ semsg(_(e_cannot_use_str_itself_it_is_imported), name);
16181623 name[len] = cc;
16191624 *lenp = 0;
16201625 return (char_u *)""; // just in case
@@ -3751,7 +3756,7 @@
37513756 {
37523757 len = (int)STRLEN(lv.ll_exp_name);
37533758 name = deref_func_name(lv.ll_exp_name, &len, partial, type,
3754- flags & TFN_NO_AUTOLOAD, NULL);
3759+ flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL);
37553760 if (name == lv.ll_exp_name)
37563761 name = NULL;
37573762 }
@@ -3783,7 +3788,7 @@
37833788 {
37843789 len = (int)(end - *pp);
37853790 name = deref_func_name(*pp, &len, partial, type,
3786- flags & TFN_NO_AUTOLOAD, NULL);
3791+ flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL);
37873792 if (name == *pp)
37883793 name = NULL;
37893794 }
@@ -4146,7 +4151,7 @@
41464151 else
41474152 {
41484153 name = save_function_name(&p, &is_global, eap->skip,
4149- TFN_NO_AUTOLOAD, &fudi);
4154+ TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi);
41504155 paren = (vim_strchr(p, '(') != NULL);
41514156 if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)
41524157 {
@@ -5199,7 +5204,8 @@
51995204 // from trans_function_name().
52005205 len = (int)STRLEN(tofree);
52015206 name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial,
5202- in_vim9script() && type == NULL ? &type : NULL, FALSE, &found_var);
5207+ in_vim9script() && type == NULL ? &type : NULL,
5208+ FALSE, FALSE, &found_var);
52035209
52045210 // Skip white space to allow ":call func ()". Not good, but required for
52055211 // backward compatibility.
diff -r d0ce0a7ce04c -r 73232ed49cf2 src/version.c
--- a/src/version.c Wed Jan 19 14:45:05 2022 +0100
+++ b/src/version.c Wed Jan 19 18:30:05 2022 +0100
@@ -751,6 +751,8 @@
751751 static int included_patches[] =
752752 { /* Add new patch number below this line */
753753 /**/
754+ 4145,
755+/**/
754756 4144,
755757 /**/
756758 4143,
diff -r d0ce0a7ce04c -r 73232ed49cf2 src/vim.h
--- a/src/vim.h Wed Jan 19 14:45:05 2022 +0100
+++ b/src/vim.h Wed Jan 19 18:30:05 2022 +0100
@@ -2632,6 +2632,7 @@
26322632 #define TFN_READ_ONLY 0x10 // will not change the var
26332633 #define TFN_NO_DECL 0x20 // only used for GLV_NO_DECL
26342634 #define TFN_COMPILING 0x40 // only used for GLV_COMPILING
2635+#define TFN_NEW_FUNC 0x80 // defining a new function
26352636
26362637 // Values for get_lval() flags argument:
26372638 #define GLV_QUIET TFN_QUIET // no error messages
Afficher sur ancien navigateur de dépôt.