Patch 8.2.1515
Problem:    Vim9: can create s:var in legacy script but cannot unlet.
Solution:   Allow :unlet for legacy script var.
Files:      src/vim9compile.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.1514/src/vim9compile.c   2020-08-22 19:01:57.608441927 +0200
--- src/vim9compile.c   2020-08-23 15:16:23.987812856 +0200
***************
*** 259,264 ****
--- 259,273 ----
  }
  
  /*
+  * Returnd TRUE if the script context is Vim9 script.
+  */
+     static int
+ script_is_vim9()
+ {
+     return SCRIPT_ITEM(current_sctx.sc_sid)->sn_version == 
SCRIPT_VERSION_VIM9;
+ }
+ 
+ /*
   * Lookup a variable in the current script.
   * If "vim9script" is TRUE the script must be Vim9 script.  Used for "var"
   * without "s:".
***************
*** 271,278 ****
      hashtab_T     *ht = &SCRIPT_VARS(current_sctx.sc_sid);
      dictitem_T            *di;
  
!     if (vim9script && SCRIPT_ITEM(current_sctx.sc_sid)->sn_version
!                                                       != SCRIPT_VERSION_VIM9)
        return FAIL;
      cc = name[len];
      name[len] = NUL;
--- 280,286 ----
      hashtab_T     *ht = &SCRIPT_VARS(current_sctx.sc_sid);
      dictitem_T            *di;
  
!     if (vim9script && !script_is_vim9())
        return FAIL;
      cc = name[len];
      name[len] = NUL;
***************
*** 5234,5239 ****
--- 5242,5250 ----
  {
      if (name[1] != ':' || vim_strchr((char_u *)"gwtb", *name) == NULL)
      {
+       // "unlet s:var" is allowed in legacy script.
+       if (*name == 's' && !script_is_vim9())
+           return OK;
        semsg(_(e_cannot_unlet_str), name);
        return FAIL;
      }
*** ../vim-8.2.1514/src/testdir/test_vim9_script.vim    2020-08-21 
21:55:39.339649975 +0200
--- src/testdir/test_vim9_script.vim    2020-08-23 15:19:44.311252281 +0200
***************
*** 608,613 ****
--- 608,620 ----
    assert_false(exists('g:somevar'))
    unlet! g:somevar
  
+   # also works for script-local variable in legacy Vim script
+   s:somevar = 'legacy'
+   assert_true(exists('s:somevar'))
+   unlet s:somevar
+   assert_false(exists('s:somevar'))
+   unlet! s:somevar
+ 
    call CheckScriptFailure([
          'vim9script',
          'let svar = 123',
*** ../vim-8.2.1514/src/version.c       2020-08-23 15:09:31.808967049 +0200
--- src/version.c       2020-08-23 15:20:49.182988476 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     1515,
  /**/

-- 
This sentence is not sure that it exists, but if it does, it will
certainly consider the possibility that other sentences exist.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202008231322.07NDMOgc980173%40masaka.moolenaar.net.

Raspunde prin e-mail lui