Mirror of the Vim source from https://github.com/vim/vim
Révision | 73232ed49cf2dcd895ba918c2f31efd0a36f3760 (tree) |
---|---|
l'heure | 2022-01-20 02:30:05 |
Auteur | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
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
@@ -2072,7 +2072,7 @@ | ||
2072 | 2072 | // If "s" is the name of a variable of type VAR_FUNC |
2073 | 2073 | // use its contents. |
2074 | 2074 | s = deref_func_name(s, &len, &partial, |
2075 | - in_vim9script() ? &type : NULL, !evaluate, &found_var); | |
2075 | + in_vim9script() ? &type : NULL, !evaluate, FALSE, &found_var); | |
2076 | 2076 | |
2077 | 2077 | // Need to make a copy, in case evaluating the arguments makes |
2078 | 2078 | // the name invalid. |
@@ -4,7 +4,7 @@ | ||
4 | 4 | char_u *get_lambda_name(void); |
5 | 5 | char_u *register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state); |
6 | 6 | 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); | |
8 | 8 | void emsg_funcname(char *ermsg, char_u *name); |
9 | 9 | int get_func_tv(char_u *name, int len, typval_T *rettv, char_u **arg, evalarg_T *evalarg, funcexe_T *funcexe); |
10 | 10 | char_u *fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error); |
@@ -458,6 +458,16 @@ | ||
458 | 458 | CheckDefAndScriptFailure(lines, ['E1094:', 'E1236: Cannot use That itself']) |
459 | 459 | |
460 | 460 | 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 | |
461 | 471 | import './Xthat.vim' as one |
462 | 472 | import './Xthat.vim' as two |
463 | 473 | END |
@@ -1000,7 +1010,7 @@ | ||
1000 | 1010 | echo 'local to function' |
1001 | 1011 | enddef |
1002 | 1012 | END |
1003 | - CheckScriptFailure(lines, 'E1236:') | |
1013 | + CheckScriptFailure(lines, 'E1213: Redefining imported item "Func"') | |
1004 | 1014 | |
1005 | 1015 | lines =<< trim END |
1006 | 1016 | vim9script |
@@ -1567,6 +1567,7 @@ | ||
1567 | 1567 | * "partialp". |
1568 | 1568 | * If "type" is not NULL and a Vim9 script-local variable is found look up the |
1569 | 1569 | * type of the variable. |
1570 | + * If "new_function" is TRUE the name is for a new function. | |
1570 | 1571 | * If "found_var" is not NULL and a variable was found set it to TRUE. |
1571 | 1572 | */ |
1572 | 1573 | char_u * |
@@ -1576,6 +1577,7 @@ | ||
1576 | 1577 | partial_T **partialp, |
1577 | 1578 | type_T **type, |
1578 | 1579 | int no_autoload, |
1580 | + int new_function, | |
1579 | 1581 | int *found_var) |
1580 | 1582 | { |
1581 | 1583 | dictitem_T *v; |
@@ -1614,7 +1616,10 @@ | ||
1614 | 1616 | if (import != NULL) |
1615 | 1617 | { |
1616 | 1618 | 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); | |
1618 | 1623 | name[len] = cc; |
1619 | 1624 | *lenp = 0; |
1620 | 1625 | return (char_u *)""; // just in case |
@@ -3751,7 +3756,7 @@ | ||
3751 | 3756 | { |
3752 | 3757 | len = (int)STRLEN(lv.ll_exp_name); |
3753 | 3758 | 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); | |
3755 | 3760 | if (name == lv.ll_exp_name) |
3756 | 3761 | name = NULL; |
3757 | 3762 | } |
@@ -3783,7 +3788,7 @@ | ||
3783 | 3788 | { |
3784 | 3789 | len = (int)(end - *pp); |
3785 | 3790 | name = deref_func_name(*pp, &len, partial, type, |
3786 | - flags & TFN_NO_AUTOLOAD, NULL); | |
3791 | + flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL); | |
3787 | 3792 | if (name == *pp) |
3788 | 3793 | name = NULL; |
3789 | 3794 | } |
@@ -4146,7 +4151,7 @@ | ||
4146 | 4151 | else |
4147 | 4152 | { |
4148 | 4153 | name = save_function_name(&p, &is_global, eap->skip, |
4149 | - TFN_NO_AUTOLOAD, &fudi); | |
4154 | + TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi); | |
4150 | 4155 | paren = (vim_strchr(p, '(') != NULL); |
4151 | 4156 | if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) |
4152 | 4157 | { |
@@ -5199,7 +5204,8 @@ | ||
5199 | 5204 | // from trans_function_name(). |
5200 | 5205 | len = (int)STRLEN(tofree); |
5201 | 5206 | 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); | |
5203 | 5209 | |
5204 | 5210 | // Skip white space to allow ":call func ()". Not good, but required for |
5205 | 5211 | // backward compatibility. |
@@ -751,6 +751,8 @@ | ||
751 | 751 | static int included_patches[] = |
752 | 752 | { /* Add new patch number below this line */ |
753 | 753 | /**/ |
754 | + 4145, | |
755 | +/**/ | |
754 | 756 | 4144, |
755 | 757 | /**/ |
756 | 758 | 4143, |
@@ -2632,6 +2632,7 @@ | ||
2632 | 2632 | #define TFN_READ_ONLY 0x10 // will not change the var |
2633 | 2633 | #define TFN_NO_DECL 0x20 // only used for GLV_NO_DECL |
2634 | 2634 | #define TFN_COMPILING 0x40 // only used for GLV_COMPILING |
2635 | +#define TFN_NEW_FUNC 0x80 // defining a new function | |
2635 | 2636 | |
2636 | 2637 | // Values for get_lval() flags argument: |
2637 | 2638 | #define GLV_QUIET TFN_QUIET // no error messages |