To: vim_dev@googlegroups.com Subject: Patch 8.2.0602 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.0602 Problem: :unlet $VAR does not work properly. Solution: Make ":lockvar $VAR" fail. Check the "skip" flag. Files: src/evalvars.c, src/globals.h, src/testdir/test_vimscript.vim *** ../vim-8.2.0601/src/evalvars.c 2020-04-19 16:28:55.296495996 +0200 --- src/evalvars.c 2020-04-19 17:19:54.777774105 +0200 *************** *** 1417,1430 **** { if (*arg == '$') { ! char_u *name = ++arg; ! if (get_env_len(&arg) == 0) { ! semsg(_(e_invarg2), name - 1); return; } ! vim_unsetenv(name); arg = skipwhite(arg); continue; } --- 1417,1433 ---- { if (*arg == '$') { ! lv.ll_name = arg; ! lv.ll_tv = NULL; ! ++arg; if (get_env_len(&arg) == 0) { ! semsg(_(e_invarg2), arg - 1); return; } ! if (!error && !eap->skip ! && callback(&lv, arg, eap, deep, cookie) == FAIL) ! error = TRUE; arg = skipwhite(arg); continue; } *************** *** 1477,1484 **** cc = *name_end; *name_end = NUL; ! // Normal name or expanded name. ! if (do_unlet(lp->ll_name, forceit) == FAIL) ret = FAIL; *name_end = cc; } --- 1480,1489 ---- cc = *name_end; *name_end = NUL; ! // Environment variable, normal name or expanded name. ! if (*lp->ll_name == '$') ! vim_unsetenv(lp->ll_name + 1); ! else if (do_unlet(lp->ll_name, forceit) == FAIL) ret = FAIL; *name_end = cc; } *************** *** 1608,1631 **** { cc = *name_end; *name_end = NUL; ! ! // Normal name or expanded name. ! di = find_var(lp->ll_name, NULL, TRUE); ! if (di == NULL) ret = FAIL; ! else if ((di->di_flags & DI_FLAGS_FIX) ! && di->di_tv.v_type != VAR_DICT ! && di->di_tv.v_type != VAR_LIST) ! // For historic reasons this error is not given for a list or dict. ! // E.g., the b: dict could be locked/unlocked. ! semsg(_("E940: Cannot lock or unlock variable %s"), lp->ll_name); else { ! if (lock) ! di->di_flags |= DI_FLAGS_LOCK; else ! di->di_flags &= ~DI_FLAGS_LOCK; ! item_lock(&di->di_tv, deep, lock); } *name_end = cc; } --- 1613,1646 ---- { cc = *name_end; *name_end = NUL; ! if (*lp->ll_name == '$') ! { ! semsg(_(e_lock_unlock), lp->ll_name); ret = FAIL; ! } else { ! // Normal name or expanded name. ! di = find_var(lp->ll_name, NULL, TRUE); ! if (di == NULL) ! ret = FAIL; ! else if ((di->di_flags & DI_FLAGS_FIX) ! && di->di_tv.v_type != VAR_DICT ! && di->di_tv.v_type != VAR_LIST) ! { ! // For historic reasons this error is not given for a list or ! // dict. E.g., the b: dict could be locked/unlocked. ! semsg(_(e_lock_unlock), lp->ll_name); ! ret = FAIL; ! } else ! { ! if (lock) ! di->di_flags |= DI_FLAGS_LOCK; ! else ! di->di_flags &= ~DI_FLAGS_LOCK; ! item_lock(&di->di_tv, deep, lock); ! } } *name_end = cc; } *** ../vim-8.2.0601/src/globals.h 2020-04-13 18:25:05.614342830 +0200 --- src/globals.h 2020-04-19 17:09:42.535157001 +0200 *************** *** 1749,1754 **** --- 1749,1755 ---- EXTERN char e_continue[] INIT(= N_("E586: :continue without :while or :for")); EXTERN char e_break[] INIT(= N_("E587: :break without :while or :for")); EXTERN char e_nowhitespace[] INIT(= N_("E274: No white space allowed before parenthesis")); + EXTERN char e_lock_unlock[] INIT(= N_("E940: Cannot lock or unlock variable %s")); #endif #ifdef FEAT_GUI_MAC *** ../vim-8.2.0601/src/testdir/test_vimscript.vim 2020-04-12 13:50:22.832171856 +0200 --- src/testdir/test_vimscript.vim 2020-04-19 17:19:48.157789071 +0200 *************** *** 1711,1716 **** --- 1711,1730 ---- let @/ = '' endfunc + func Test_unlet_env() + let $TESTVAR = 'yes' + call assert_equal('yes', $TESTVAR) + call assert_fails('lockvar $TESTVAR', 'E940') + call assert_fails('unlockvar $TESTVAR', 'E940') + call assert_equal('yes', $TESTVAR) + if 0 + unlet $TESTVAR + endif + call assert_equal('yes', $TESTVAR) + unlet $TESTVAR + call assert_equal('', $TESTVAR) + endfunc + func Test_refcount() " Immediate values call assert_equal(-1, test_refcount(1)) *** ../vim-8.2.0601/src/version.c 2020-04-19 16:28:55.296495996 +0200 --- src/version.c 2020-04-19 17:01:04.112323004 +0200 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 602, /**/ -- I recommend ordering large cargo containers of paper towels to make up whatever budget underruns you have. Paper products are always useful and they have the advantage of being completely flushable if you need to make room in the storage area later. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@Moolenaar.net -- 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 ///