Skip to content

Commit 8436773

Browse files
committed
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.
1 parent dc0cf1d commit 8436773

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/testdir/test_vim9_script.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -608,6 +608,13 @@ def Test_unlet()
608608
assert_false(exists('g:somevar'))
609609
unlet! g:somevar
610610

611+
# also works for script-local variable in legacy Vim script
612+
s:somevar = 'legacy'
613+
assert_true(exists('s:somevar'))
614+
unlet s:somevar
615+
assert_false(exists('s:somevar'))
616+
unlet! s:somevar
617+
611618
call CheckScriptFailure([
612619
'vim9script',
613620
'let svar = 123',

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,8 @@ static char *(features[]) =
754754

755755
static int included_patches[] =
756756
{ /* Add new patch number below this line */
757+
/**/
758+
1515,
757759
/**/
758760
1514,
759761
/**/

src/vim9compile.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ lookup_arg(
258258
return FAIL;
259259
}
260260

261+
/*
262+
* Returnd TRUE if the script context is Vim9 script.
263+
*/
264+
static int
265+
script_is_vim9()
266+
{
267+
return SCRIPT_ITEM(current_sctx.sc_sid)->sn_version == SCRIPT_VERSION_VIM9;
268+
}
269+
261270
/*
262271
* Lookup a variable in the current script.
263272
* 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)
271280
hashtab_T *ht = &SCRIPT_VARS(current_sctx.sc_sid);
272281
dictitem_T *di;
273282

274-
if (vim9script && SCRIPT_ITEM(current_sctx.sc_sid)->sn_version
275-
!= SCRIPT_VERSION_VIM9)
283+
if (vim9script && !script_is_vim9())
276284
return FAIL;
277285
cc = name[len];
278286
name[len] = NUL;
@@ -5234,6 +5242,9 @@ check_vim9_unlet(char_u *name)
52345242
{
52355243
if (name[1] != ':' || vim_strchr((char_u *)"gwtb", *name) == NULL)
52365244
{
5245+
// "unlet s:var" is allowed in legacy script.
5246+
if (*name == 's' && !script_is_vim9())
5247+
return OK;
52375248
semsg(_(e_cannot_unlet_str), name);
52385249
return FAIL;
52395250
}

0 commit comments

Comments
 (0)