diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-12-18 15:38:00 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-12-18 15:38:00 +0100 |
commit | 9aed729fe9e62536236875a42fb170d2c8fb3046 (patch) | |
tree | 597232f50b0ec43af1c922800748a5d72b18a994 | |
parent | b5b77378bc35cb268c384e98c59f2bf8cb406270 (diff) | |
download | vim-git-9aed729fe9e62536236875a42fb170d2c8fb3046.tar.gz |
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a functionv8.2.2157
Problem: Vim9: can delete a Vim9 script variable from a function.
Solution: Check the variable is defined in Vim9 script. (closes #7483)
-rw-r--r-- | src/evalvars.c | 10 | ||||
-rw-r--r-- | src/testdir/test_vim9_assign.vim | 8 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 20 insertions, 0 deletions
diff --git a/src/evalvars.c b/src/evalvars.c index 9e11578e1..fde80d750 100644 --- a/src/evalvars.c +++ b/src/evalvars.c @@ -1663,10 +1663,20 @@ do_unlet(char_u *name, int forceit) dict_T *d; dictitem_T *di; + // can't :unlet a script variable in Vim9 script if (in_vim9script() && check_vim9_unlet(name) == FAIL) return FAIL; 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) { d = get_current_funccal_dict(ht); diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim index 60c8fe958..ad7b85b5f 100644 --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -1211,6 +1211,14 @@ def Test_unlet() CheckScriptFailure([ 'vim9script', 'var svar = 123', + 'func Func()', + ' unlet s:svar', + 'endfunc', + 'Func()', + ], 'E1081:') + CheckScriptFailure([ + 'vim9script', + 'var svar = 123', 'def Func()', ' unlet s:svar', 'enddef', diff --git a/src/version.c b/src/version.c index be2b33c19..70ff9a457 100644 --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2157, +/**/ 2156, /**/ 2155, |