Skip to content

Commit 9aed729

Browse files
committed
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function
Problem: Vim9: can delete a Vim9 script variable from a function. Solution: Check the variable is defined in Vim9 script. (closes #7483)
1 parent b5b7737 commit 9aed729

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/evalvars.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,10 +1663,20 @@ do_unlet(char_u *name, int forceit)
16631663
dict_T *d;
16641664
dictitem_T *di;
16651665

1666+
// can't :unlet a script variable in Vim9 script
16661667
if (in_vim9script() && check_vim9_unlet(name) == FAIL)
16671668
return FAIL;
16681669

16691670
ht = find_var_ht(name, &varname);
1671+
1672+
// can't :unlet a script variable in Vim9 script from a function
1673+
if (ht == get_script_local_ht()
1674+
&& SCRIPT_ID_VALID(current_sctx.sc_sid)
1675+
&& SCRIPT_ITEM(current_sctx.sc_sid)->sn_version
1676+
== SCRIPT_VERSION_VIM9
1677+
&& check_vim9_unlet(name) == FAIL)
1678+
return FAIL;
1679+
16701680
if (ht != NULL && *varname != NUL)
16711681
{
16721682
d = get_current_funccal_dict(ht);

src/testdir/test_vim9_assign.vim

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,6 +1208,14 @@ def Test_unlet()
12081208
'enddef',
12091209
'defcompile',
12101210
], 'E1081:')
1211+
CheckScriptFailure([
1212+
'vim9script',
1213+
'var svar = 123',
1214+
'func Func()',
1215+
' unlet s:svar',
1216+
'endfunc',
1217+
'Func()',
1218+
], 'E1081:')
12111219
CheckScriptFailure([
12121220
'vim9script',
12131221
'var svar = 123',

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2157,
753755
/**/
754756
2156,
755757
/**/

0 commit comments

Comments
 (0)