]> granicus.if.org Git - vim/commitdiff
patch 8.2.2157: Vim9: can delete a Vim9 script variable from a function v8.2.2157
authorBram Moolenaar <Bram@vim.org>
Fri, 18 Dec 2020 14:38:00 +0000 (15:38 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 18 Dec 2020 14:38:00 +0000 (15:38 +0100)
Problem:    Vim9: can delete a Vim9 script variable from a function.
Solution:   Check the variable is defined in Vim9 script. (closes #7483)

src/evalvars.c
src/testdir/test_vim9_assign.vim
src/version.c

index 9e11578e13c01cfaede3d3f2f225aa517220daed..fde80d750d169ea364c352ad3e5c040f185e4d92 100644 (file)
@@ -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);
index 60c8fe958959f296ea7587f690ead214a0978b28..ad7b85b5fcd292bd9cae661b67896d913d5f9e00 100644 (file)
@@ -1208,6 +1208,14 @@ def Test_unlet()
    'enddef',
    'defcompile',
    ], 'E1081:')
+  CheckScriptFailure([
+   'vim9script',
+   'var svar = 123',
+   'func Func()',
+   '  unlet s:svar',
+   'endfunc',
+   'Func()',
+   ], 'E1081:')
   CheckScriptFailure([
    'vim9script',
    'var svar = 123',
index be2b33c19d934c77ceed8cf9e5e5a202a6d58718..70ff9a457e3205358745d7f3f81c86ce04889d56 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2157,
 /**/
     2156,
 /**/