Mercurial > vim
comparison src/userfunc.c @ 27233:73232ed49cf2 v8.2.4145
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().
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 19 Jan 2022 18:30:05 +0100 |
parents | a10936038ec9 |
children | 322b79b002b7 |
comparison
equal
deleted
inserted
replaced
27232:d0ce0a7ce04c | 27233:73232ed49cf2 |
---|---|
1565 * name it contains, otherwise return "name". | 1565 * name it contains, otherwise return "name". |
1566 * If "partialp" is not NULL, and "name" is of type VAR_PARTIAL also set | 1566 * If "partialp" is not NULL, and "name" is of type VAR_PARTIAL also set |
1567 * "partialp". | 1567 * "partialp". |
1568 * If "type" is not NULL and a Vim9 script-local variable is found look up the | 1568 * If "type" is not NULL and a Vim9 script-local variable is found look up the |
1569 * type of the variable. | 1569 * type of the variable. |
1570 * If "new_function" is TRUE the name is for a new function. | |
1570 * If "found_var" is not NULL and a variable was found set it to TRUE. | 1571 * If "found_var" is not NULL and a variable was found set it to TRUE. |
1571 */ | 1572 */ |
1572 char_u * | 1573 char_u * |
1573 deref_func_name( | 1574 deref_func_name( |
1574 char_u *name, | 1575 char_u *name, |
1575 int *lenp, | 1576 int *lenp, |
1576 partial_T **partialp, | 1577 partial_T **partialp, |
1577 type_T **type, | 1578 type_T **type, |
1578 int no_autoload, | 1579 int no_autoload, |
1580 int new_function, | |
1579 int *found_var) | 1581 int *found_var) |
1580 { | 1582 { |
1581 dictitem_T *v; | 1583 dictitem_T *v; |
1582 typval_T *tv = NULL; | 1584 typval_T *tv = NULL; |
1583 int cc; | 1585 int cc; |
1612 | 1614 |
1613 // imported function from another script | 1615 // imported function from another script |
1614 if (import != NULL) | 1616 if (import != NULL) |
1615 { | 1617 { |
1616 name[len] = NUL; | 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 name[len] = cc; | 1623 name[len] = cc; |
1619 *lenp = 0; | 1624 *lenp = 0; |
1620 return (char_u *)""; // just in case | 1625 return (char_u *)""; // just in case |
1621 } | 1626 } |
1622 } | 1627 } |
3749 // Check if the name is a Funcref. If so, use the value. | 3754 // Check if the name is a Funcref. If so, use the value. |
3750 if (lv.ll_exp_name != NULL) | 3755 if (lv.ll_exp_name != NULL) |
3751 { | 3756 { |
3752 len = (int)STRLEN(lv.ll_exp_name); | 3757 len = (int)STRLEN(lv.ll_exp_name); |
3753 name = deref_func_name(lv.ll_exp_name, &len, partial, type, | 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 if (name == lv.ll_exp_name) | 3760 if (name == lv.ll_exp_name) |
3756 name = NULL; | 3761 name = NULL; |
3757 } | 3762 } |
3758 else if (lv.ll_sid > 0) | 3763 else if (lv.ll_sid > 0) |
3759 { | 3764 { |
3781 } | 3786 } |
3782 else if (!(flags & TFN_NO_DEREF)) | 3787 else if (!(flags & TFN_NO_DEREF)) |
3783 { | 3788 { |
3784 len = (int)(end - *pp); | 3789 len = (int)(end - *pp); |
3785 name = deref_func_name(*pp, &len, partial, type, | 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 if (name == *pp) | 3792 if (name == *pp) |
3788 name = NULL; | 3793 name = NULL; |
3789 } | 3794 } |
3790 if (name != NULL) | 3795 if (name != NULL) |
3791 { | 3796 { |
4144 CLEAR_FIELD(fudi); | 4149 CLEAR_FIELD(fudi); |
4145 } | 4150 } |
4146 else | 4151 else |
4147 { | 4152 { |
4148 name = save_function_name(&p, &is_global, eap->skip, | 4153 name = save_function_name(&p, &is_global, eap->skip, |
4149 TFN_NO_AUTOLOAD, &fudi); | 4154 TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi); |
4150 paren = (vim_strchr(p, '(') != NULL); | 4155 paren = (vim_strchr(p, '(') != NULL); |
4151 if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) | 4156 if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) |
4152 { | 4157 { |
4153 /* | 4158 /* |
4154 * Return on an invalid expression in braces, unless the expression | 4159 * Return on an invalid expression in braces, unless the expression |
5197 // If it is the name of a variable of type VAR_FUNC or VAR_PARTIAL use its | 5202 // If it is the name of a variable of type VAR_FUNC or VAR_PARTIAL use its |
5198 // contents. For VAR_PARTIAL get its partial, unless we already have one | 5203 // contents. For VAR_PARTIAL get its partial, unless we already have one |
5199 // from trans_function_name(). | 5204 // from trans_function_name(). |
5200 len = (int)STRLEN(tofree); | 5205 len = (int)STRLEN(tofree); |
5201 name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial, | 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 // Skip white space to allow ":call func ()". Not good, but required for | 5210 // Skip white space to allow ":call func ()". Not good, but required for |
5205 // backward compatibility. | 5211 // backward compatibility. |
5206 startarg = skipwhite(arg); | 5212 startarg = skipwhite(arg); |
5207 if (*startarg != '(') | 5213 if (*startarg != '(') |