mirror of
https://github.com/vim/vim.git
synced 2025-09-28 04:24:06 -04:00
patch 8.2.2734: Vim9: cannot use legacy script-local var from :def function
Problem: Vim9: cannot use legacy script-local var from :def function. Solution: Do not insist on using "s:" prefix. (closes #8076)
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
/* vim9compile.c */
|
/* vim9compile.c */
|
||||||
int script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx);
|
|
||||||
int check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg);
|
int check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg);
|
||||||
int check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2);
|
int check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2);
|
||||||
int use_typecheck(type_T *actual, type_T *expected);
|
int use_typecheck(type_T *actual, type_T *expected);
|
||||||
|
@@ -2714,6 +2714,21 @@ def Test_expr7_negate_add()
|
|||||||
CheckDefAndScriptFailure(lines, 'E1050:')
|
CheckDefAndScriptFailure(lines, 'E1050:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_expr7_legacy_script()
|
||||||
|
var lines =<< trim END
|
||||||
|
let s:legacy = 'legacy'
|
||||||
|
def GetLocal(): string
|
||||||
|
return legacy
|
||||||
|
enddef
|
||||||
|
def GetLocalPrefix(): string
|
||||||
|
return s:legacy
|
||||||
|
enddef
|
||||||
|
call assert_equal('legacy', GetLocal())
|
||||||
|
call assert_equal('legacy', GetLocalPrefix())
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Echo(arg: any): string
|
def Echo(arg: any): string
|
||||||
return arg
|
return arg
|
||||||
enddef
|
enddef
|
||||||
|
@@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2734,
|
||||||
/**/
|
/**/
|
||||||
2733,
|
2733,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -332,22 +332,15 @@ script_is_vim9()
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Lookup a variable (without s: prefix) in the current script.
|
* Lookup a variable (without s: prefix) in the current script.
|
||||||
* If "vim9script" is TRUE the script must be Vim9 script. Used for "var"
|
|
||||||
* without "s:".
|
|
||||||
* "cctx" is NULL at the script level.
|
* "cctx" is NULL at the script level.
|
||||||
* Returns OK or FAIL.
|
* Returns OK or FAIL.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
script_var_exists(char_u *name, size_t len, int vim9script, cctx_T *cctx)
|
script_var_exists(char_u *name, size_t len, cctx_T *cctx)
|
||||||
{
|
{
|
||||||
int is_vim9_script;
|
|
||||||
|
|
||||||
if (current_sctx.sc_sid <= 0)
|
if (current_sctx.sc_sid <= 0)
|
||||||
return FAIL;
|
return FAIL;
|
||||||
is_vim9_script = script_is_vim9();
|
if (script_is_vim9())
|
||||||
if (vim9script && !is_vim9_script)
|
|
||||||
return FAIL;
|
|
||||||
if (is_vim9_script)
|
|
||||||
{
|
{
|
||||||
// Check script variables that were visible where the function was
|
// Check script variables that were visible where the function was
|
||||||
// defined.
|
// defined.
|
||||||
@@ -382,7 +375,7 @@ variable_exists(char_u *name, size_t len, cctx_T *cctx)
|
|||||||
return (cctx != NULL
|
return (cctx != NULL
|
||||||
&& (lookup_local(name, len, NULL, cctx) == OK
|
&& (lookup_local(name, len, NULL, cctx) == OK
|
||||||
|| arg_exists(name, len, NULL, NULL, NULL, cctx) == OK))
|
|| arg_exists(name, len, NULL, NULL, NULL, cctx) == OK))
|
||||||
|| script_var_exists(name, len, FALSE, cctx) == OK
|
|| script_var_exists(name, len, cctx) == OK
|
||||||
|| find_imported(name, len, cctx) != NULL;
|
|| find_imported(name, len, cctx) != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,7 +422,7 @@ check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg)
|
|||||||
int c = p[len];
|
int c = p[len];
|
||||||
ufunc_T *ufunc = NULL;
|
ufunc_T *ufunc = NULL;
|
||||||
|
|
||||||
if (script_var_exists(p, len, FALSE, cctx) == OK)
|
if (script_var_exists(p, len, cctx) == OK)
|
||||||
{
|
{
|
||||||
if (is_arg)
|
if (is_arg)
|
||||||
semsg(_(e_argument_already_declared_in_script_str), p);
|
semsg(_(e_argument_already_declared_in_script_str), p);
|
||||||
@@ -2990,7 +2983,7 @@ compile_load(
|
|||||||
{
|
{
|
||||||
// "var" can be script-local even without using "s:" if it
|
// "var" can be script-local even without using "s:" if it
|
||||||
// already exists in a Vim9 script or when it's imported.
|
// already exists in a Vim9 script or when it's imported.
|
||||||
if (script_var_exists(*arg, len, TRUE, cctx) == OK
|
if (script_var_exists(*arg, len, cctx) == OK
|
||||||
|| find_imported(name, 0, cctx) != NULL)
|
|| find_imported(name, 0, cctx) != NULL)
|
||||||
res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE);
|
res = compile_load_scriptvar(cctx, name, *arg, &end, FALSE);
|
||||||
|
|
||||||
@@ -5844,9 +5837,9 @@ compile_lhs(
|
|||||||
&& STRNCMP(var_start, "s:", 2) == 0;
|
&& STRNCMP(var_start, "s:", 2) == 0;
|
||||||
int script_var = (script_namespace
|
int script_var = (script_namespace
|
||||||
? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
|
? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
|
||||||
FALSE, cctx)
|
cctx)
|
||||||
: script_var_exists(var_start, lhs->lhs_varlen,
|
: script_var_exists(var_start, lhs->lhs_varlen,
|
||||||
FALSE, cctx)) == OK;
|
cctx)) == OK;
|
||||||
imported_T *import =
|
imported_T *import =
|
||||||
find_imported(var_start, lhs->lhs_varlen, cctx);
|
find_imported(var_start, lhs->lhs_varlen, cctx);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user