mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Problem: Vim9: can create s:var in legacy script but cannot unlet. Solution: Allow :unlet for legacy script var.
This commit is contained in:
@@ -608,6 +608,13 @@ def Test_unlet()
|
|||||||
assert_false(exists('g:somevar'))
|
assert_false(exists('g:somevar'))
|
||||||
unlet! g:somevar
|
unlet! g:somevar
|
||||||
|
|
||||||
|
# also works for script-local variable in legacy Vim script
|
||||||
|
s:somevar = 'legacy'
|
||||||
|
assert_true(exists('s:somevar'))
|
||||||
|
unlet s:somevar
|
||||||
|
assert_false(exists('s:somevar'))
|
||||||
|
unlet! s:somevar
|
||||||
|
|
||||||
call CheckScriptFailure([
|
call CheckScriptFailure([
|
||||||
'vim9script',
|
'vim9script',
|
||||||
'let svar = 123',
|
'let svar = 123',
|
||||||
|
@@ -754,6 +754,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 */
|
||||||
|
/**/
|
||||||
|
1515,
|
||||||
/**/
|
/**/
|
||||||
1514,
|
1514,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -258,6 +258,15 @@ lookup_arg(
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returnd TRUE if the script context is Vim9 script.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
script_is_vim9()
|
||||||
|
{
|
||||||
|
return SCRIPT_ITEM(current_sctx.sc_sid)->sn_version == SCRIPT_VERSION_VIM9;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Lookup a variable in the current script.
|
* Lookup a variable in the current script.
|
||||||
* If "vim9script" is TRUE the script must be Vim9 script. Used for "var"
|
* If "vim9script" is TRUE the script must be Vim9 script. Used for "var"
|
||||||
@@ -271,8 +280,7 @@ lookup_script(char_u *name, size_t len, int vim9script)
|
|||||||
hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid);
|
hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid);
|
||||||
dictitem_T *di;
|
dictitem_T *di;
|
||||||
|
|
||||||
if (vim9script && SCRIPT_ITEM(current_sctx.sc_sid)->sn_version
|
if (vim9script && !script_is_vim9())
|
||||||
!= SCRIPT_VERSION_VIM9)
|
|
||||||
return FAIL;
|
return FAIL;
|
||||||
cc = name[len];
|
cc = name[len];
|
||||||
name[len] = NUL;
|
name[len] = NUL;
|
||||||
@@ -5234,6 +5242,9 @@ check_vim9_unlet(char_u *name)
|
|||||||
{
|
{
|
||||||
if (name[1] != ':' || vim_strchr((char_u *)"gwtb", *name) == NULL)
|
if (name[1] != ':' || vim_strchr((char_u *)"gwtb", *name) == NULL)
|
||||||
{
|
{
|
||||||
|
// "unlet s:var" is allowed in legacy script.
|
||||||
|
if (*name == 's' && !script_is_vim9())
|
||||||
|
return OK;
|
||||||
semsg(_(e_cannot_unlet_str), name);
|
semsg(_(e_cannot_unlet_str), name);
|
||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user