Patch 8.2.4145
Problem: Confusing error when using name of import for a function.
Solution: Pass a flag to trans_function_name().
Files: src/vim.h, src/userfunc.c, src/proto/userfunc.pro, src/eval.c,
src/testdir/test_vim9_import.vim
*** ../vim-8.2.4144/src/vim.h 2022-01-16 15:52:32.016847567 +0000
--- src/vim.h 2022-01-19 16:04:24.389229974 +0000
***************
*** 2632,2637 ****
--- 2632,2638 ----
#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
*** ../vim-8.2.4144/src/userfunc.c 2022-01-17 20:09:02.844881524 +0000
--- src/userfunc.c 2022-01-19 16:16:43.377490269 +0000
***************
*** 1567,1572 ****
--- 1567,1573 ----
* "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,1581 ****
--- 1577,1583 ----
partial_T **partialp,
type_T **type,
int no_autoload,
+ int new_function,
int *found_var)
{
dictitem_T *v;
***************
*** 1614,1620 ****
if (import != NULL)
{
name[len] = NUL;
! semsg(_(e_cannot_use_str_itself_it_is_imported), name);
name[len] = cc;
*lenp = 0;
return (char_u *)""; // just in case
--- 1616,1625 ----
if (import != NULL)
{
name[len] = NUL;
! 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,3757 ****
{
len = (int)STRLEN(lv.ll_exp_name);
name = deref_func_name(lv.ll_exp_name, &len, partial, type,
! flags & TFN_NO_AUTOLOAD, NULL);
if (name == lv.ll_exp_name)
name = NULL;
}
--- 3756,3762 ----
{
len = (int)STRLEN(lv.ll_exp_name);
name = deref_func_name(lv.ll_exp_name, &len, partial, type,
! flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL);
if (name == lv.ll_exp_name)
name = NULL;
}
***************
*** 3783,3789 ****
{
len = (int)(end - *pp);
name = deref_func_name(*pp, &len, partial, type,
! flags & TFN_NO_AUTOLOAD, NULL);
if (name == *pp)
name = NULL;
}
--- 3788,3794 ----
{
len = (int)(end - *pp);
name = deref_func_name(*pp, &len, partial, type,
! flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL);
if (name == *pp)
name = NULL;
}
***************
*** 4146,4152 ****
else
{
name = save_function_name(&p, &is_global, eap->skip,
! TFN_NO_AUTOLOAD, &fudi);
paren = (vim_strchr(p, '(') != NULL);
if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)
{
--- 4151,4157 ----
else
{
name = save_function_name(&p, &is_global, eap->skip,
! TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi);
paren = (vim_strchr(p, '(') != NULL);
if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)
{
***************
*** 5199,5205 ****
// 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);
// Skip white space to allow ":call func ()". Not good, but required for
// backward compatibility.
--- 5204,5211 ----
// 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, FALSE, &found_var);
// Skip white space to allow ":call func ()". Not good, but required for
// backward compatibility.
*** ../vim-8.2.4144/src/proto/userfunc.pro 2022-01-13 21:15:17.237958552
+0000
--- src/proto/userfunc.pro 2022-01-19 16:14:21.284464360 +0000
***************
*** 4,10 ****
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);
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);
--- 4,10 ----
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 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);
*** ../vim-8.2.4144/src/eval.c 2022-01-18 10:37:23.753431035 +0000
--- src/eval.c 2022-01-19 16:06:56.669913202 +0000
***************
*** 2072,2078 ****
// 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);
// Need to make a copy, in case evaluating the arguments makes
// the name invalid.
--- 2072,2078 ----
// 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, FALSE, &found_var);
// Need to make a copy, in case evaluating the arguments makes
// the name invalid.
*** ../vim-8.2.4144/src/testdir/test_vim9_import.vim 2022-01-18
17:43:01.061598437 +0000
--- src/testdir/test_vim9_import.vim 2022-01-19 17:13:25.827988584 +0000
***************
*** 458,463 ****
--- 458,473 ----
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,1006 ****
echo 'local to function'
enddef
END
! CheckScriptFailure(lines, 'E1236:')
lines =<< trim END
vim9script
--- 1010,1016 ----
echo 'local to function'
enddef
END
! CheckScriptFailure(lines, 'E1213: Redefining imported item "Func"')
lines =<< trim END
vim9script
*** ../vim-8.2.4144/src/version.c 2022-01-19 13:32:53.443929932 +0000
--- src/version.c 2022-01-19 17:19:43.208715984 +0000
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 4145,
/**/
--
FATHER: We are here today to witness the union of two young people in the
joyful bond of the holy wedlock. Unfortunately, one of them, my son
Herbert, has just fallen to his death.
[Murmurs from CROWD; the BRIDE smiles with relief, coughs.]
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20220119172157.D91431C0243%40moolenaar.net.