0
0
mirror of https://github.com/vim/vim.git synced 2025-07-25 10:54:51 -04:00

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)
This commit is contained in:
Bram Moolenaar 2020-12-18 15:38:00 +01:00
parent b5b77378bc
commit 9aed729fe9
3 changed files with 20 additions and 0 deletions

View File

@ -1663,10 +1663,20 @@ do_unlet(char_u *name, int forceit)
dict_T *d; dict_T *d;
dictitem_T *di; dictitem_T *di;
// can't :unlet a script variable in Vim9 script
if (in_vim9script() && check_vim9_unlet(name) == FAIL) if (in_vim9script() && check_vim9_unlet(name) == FAIL)
return FAIL; return FAIL;
ht = find_var_ht(name, &varname); ht = find_var_ht(name, &varname);
// can't :unlet a script variable in Vim9 script from a function
if (ht == get_script_local_ht()
&& SCRIPT_ID_VALID(current_sctx.sc_sid)
&& SCRIPT_ITEM(current_sctx.sc_sid)->sn_version
== SCRIPT_VERSION_VIM9
&& check_vim9_unlet(name) == FAIL)
return FAIL;
if (ht != NULL && *varname != NUL) if (ht != NULL && *varname != NUL)
{ {
d = get_current_funccal_dict(ht); d = get_current_funccal_dict(ht);

View File

@ -1208,6 +1208,14 @@ def Test_unlet()
'enddef', 'enddef',
'defcompile', 'defcompile',
], 'E1081:') ], 'E1081:')
CheckScriptFailure([
'vim9script',
'var svar = 123',
'func Func()',
' unlet s:svar',
'endfunc',
'Func()',
], 'E1081:')
CheckScriptFailure([ CheckScriptFailure([
'vim9script', 'vim9script',
'var svar = 123', 'var svar = 123',

View File

@ -750,6 +750,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 */
/**/
2157,
/**/ /**/
2156, 2156,
/**/ /**/