0
0
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:
Bram Moolenaar
2020-08-23 15:21:55 +02:00
parent dc0cf1db3e
commit 8436773fad
3 changed files with 22 additions and 2 deletions

View File

@@ -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',

View File

@@ -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,
/**/ /**/

View File

@@ -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;
} }