mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.2.2729: Vim9: wrong error message for referring to legacy script var
Problem: Vim9: wrong error message for referring to legacy script variable. Solution: Do allow referring to a variable in legacy script without "s:" if it exists at compile time. (closes #8076)
This commit is contained in:
@@ -1476,6 +1476,41 @@ def Test_var_declaration_fails()
|
|||||||
CheckDefFailure(['const foo: number'], 'E1021:')
|
CheckDefFailure(['const foo: number'], 'E1021:')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_script_local_in_legacy()
|
||||||
|
# OK to define script-local later when prefixed with s:
|
||||||
|
var lines =<< trim END
|
||||||
|
def SetLater()
|
||||||
|
s:legacy = 'two'
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
let s:legacy = 'one'
|
||||||
|
call SetLater()
|
||||||
|
call assert_equal('two', s:legacy)
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
# OK to leave out s: prefix when script-local already defined
|
||||||
|
lines =<< trim END
|
||||||
|
let s:legacy = 'one'
|
||||||
|
def SetNoPrefix()
|
||||||
|
legacy = 'two'
|
||||||
|
enddef
|
||||||
|
call SetNoPrefix()
|
||||||
|
call assert_equal('two', s:legacy)
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
# Not OK to leave out s: prefix when script-local defined later
|
||||||
|
lines =<< trim END
|
||||||
|
def SetLaterNoPrefix()
|
||||||
|
legacy = 'two'
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
let s:legacy = 'one'
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E476:', 1)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_var_type_check()
|
def Test_var_type_check()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
vim9script
|
vim9script
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
2729,
|
||||||
/**/
|
/**/
|
||||||
2728,
|
2728,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -5708,17 +5708,9 @@ generate_store_var(
|
|||||||
return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL);
|
return generate_STORE(cctx, ISN_STOREV, vimvaridx, NULL);
|
||||||
case dest_script:
|
case dest_script:
|
||||||
if (scriptvar_idx < 0)
|
if (scriptvar_idx < 0)
|
||||||
{
|
// "s:" may be included in the name.
|
||||||
char_u *name_s = name;
|
return generate_OLDSCRIPT(cctx, ISN_STORES, name,
|
||||||
int r;
|
|
||||||
|
|
||||||
// "s:" is included in the name.
|
|
||||||
r = generate_OLDSCRIPT(cctx, ISN_STORES, name_s,
|
|
||||||
scriptvar_sid, type);
|
scriptvar_sid, type);
|
||||||
if (name_s != name)
|
|
||||||
vim_free(name_s);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
return generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT,
|
return generate_VIM9SCRIPT(cctx, ISN_STORESCRIPT,
|
||||||
scriptvar_sid, scriptvar_idx, type);
|
scriptvar_sid, scriptvar_idx, type);
|
||||||
case dest_local:
|
case dest_local:
|
||||||
@@ -5854,7 +5846,7 @@ compile_lhs(
|
|||||||
? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
|
? script_var_exists(var_start + 2, lhs->lhs_varlen - 2,
|
||||||
FALSE, cctx)
|
FALSE, cctx)
|
||||||
: script_var_exists(var_start, lhs->lhs_varlen,
|
: script_var_exists(var_start, lhs->lhs_varlen,
|
||||||
TRUE, cctx)) == OK;
|
FALSE, 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