Skip to content

Commit

Permalink
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Browse files Browse the repository at this point in the history
Problem:    Vim9: can create s:var in legacy script but cannot unlet.
Solution:   Allow :unlet for legacy script var.
  • Loading branch information
brammool committed Aug 23, 2020
1 parent dc0cf1d commit 8436773
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/testdir/test_vim9_script.vim
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,13 @@ def Test_unlet()
assert_false(exists('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([
'vim9script',
'let svar = 123',
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1515,
/**/
1514,
/**/
Expand Down
15 changes: 13 additions & 2 deletions src/vim9compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,15 @@ lookup_arg(
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.
* If "vim9script" is TRUE the script must be Vim9 script. Used for "var"
Expand All @@ -271,8 +280,7 @@ lookup_script(char_u *name, size_t len, int vim9script)
hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid);
dictitem_T *di;

if (vim9script && SCRIPT_ITEM(current_sctx.sc_sid)->sn_version
!= SCRIPT_VERSION_VIM9)
if (vim9script && !script_is_vim9())
return FAIL;
cc = name[len];
name[len] = NUL;
Expand Down Expand Up @@ -5234,6 +5242,9 @@ check_vim9_unlet(char_u *name)
{
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);
return FAIL;
}
Expand Down

0 comments on commit 8436773

Please sign in to comment.