Mercurial > vim
changeset 21931:8e09827f8bac v8.2.1515
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Commit: https://github.com/vim/vim/commit/8436773fad285215481c4ce2b32692e66fca599f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Aug 23 15:21:55 2020 +0200
patch 8.2.1515: Vim9: can create s:var in legacy script but cannot unlet
Problem: Vim9: can create s:var in legacy script but cannot unlet.
Solution: Allow :unlet for legacy script var.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 23 Aug 2020 15:30:04 +0200 |
parents | 2345b47682bd |
children | ec8056494ff2 |
files | src/testdir/test_vim9_script.vim src/version.c src/vim9compile.c |
diffstat | 3 files changed, 22 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/testdir/test_vim9_script.vim +++ b/src/testdir/test_vim9_script.vim @@ -608,6 +608,13 @@ def Test_unlet() 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',
--- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1515, +/**/ 1514, /**/ 1513,
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -259,6 +259,15 @@ lookup_arg( } /* + * 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,8 +280,7 @@ lookup_script(char_u *name, size_t len, 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) + if (vim9script && !script_is_vim9()) return FAIL; cc = name[len]; name[len] = NUL; @@ -5234,6 +5242,9 @@ check_vim9_unlet(char_u *name) { 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; }