Patch 8.2.2193
Problem: Vim9: can change constant in :def function.
Solution: Check if a variable is locked. (issue #7526)
Files: src/evalvars.c, src/proto/evalvars.pro, src/vim9execute.c,
src/testdir/test_vim9_func.vim
*** ../vim-8.2.2192/src/evalvars.c 2020-12-19 22:10:09.857835454 +0100
--- src/evalvars.c 2020-12-22 20:28:33.810508049 +0100
***************
*** 3125,3137 ****
goto failed;
}
! // Check in this order for backwards compatibility:
! // - Whether the variable is read-only
! // - Whether the variable value is locked
! // - Whether the variable is locked
! if (var_check_ro(di->di_flags, name, FALSE)
! || value_check_lock(di->di_tv.v_lock, name, FALSE)
! || var_check_lock(di->di_flags, name, FALSE))
goto failed;
}
else
--- 3125,3131 ----
goto failed;
}
! if (var_check_permission(di, name) == FAIL)
goto failed;
}
else
***************
*** 3243,3248 ****
--- 3237,3258 ----
}
/*
+ * Check in this order for backwards compatibility:
+ * - Whether the variable is read-only
+ * - Whether the variable value is locked
+ * - Whether the variable is locked
+ */
+ int
+ var_check_permission(dictitem_T *di, char_u *name)
+ {
+ if (var_check_ro(di->di_flags, name, FALSE)
+ || value_check_lock(di->di_tv.v_lock, name, FALSE)
+ || var_check_lock(di->di_flags, name, FALSE))
+ return FAIL;
+ return OK;
+ }
+
+ /*
* Return TRUE if di_flags "flags" indicates variable "name" is read-only.
* Also give an error message.
*/
*** ../vim-8.2.2192/src/proto/evalvars.pro 2020-12-19 16:30:39.439810130
+0100
--- src/proto/evalvars.pro 2020-12-22 20:28:38.914489784 +0100
***************
*** 70,75 ****
--- 70,76 ----
void delete_var(hashtab_T *ht, hashitem_T *hi);
void set_var(char_u *name, typval_T *tv, int copy);
void set_var_const(char_u *name, type_T *type, typval_T *tv_arg, int copy,
int flags);
+ int var_check_permission(dictitem_T *di, char_u *name);
int var_check_ro(int flags, char_u *name, int use_gettext);
int var_check_lock(int flags, char_u *name, int use_gettext);
int var_check_fixed(int flags, char_u *name, int use_gettext);
*** ../vim-8.2.2192/src/vim9execute.c 2020-12-22 17:35:50.043978116 +0100
--- src/vim9execute.c 2020-12-22 20:33:58.837371149 +0100
***************
*** 1693,1700 ****
case ISN_STOREW:
case ISN_STORET:
{
! dictitem_T *di;
! hashtab_T *ht;
switch (iptr->isn_type)
{
case ISN_STOREG:
--- 1693,1702 ----
case ISN_STOREW:
case ISN_STORET:
{
! dictitem_T *di;
! hashtab_T *ht;
! char_u *name = iptr->isn_arg.string + 2;
!
switch (iptr->isn_type)
{
case ISN_STOREG:
***************
*** 1714,1724 ****
}
--ectx.ec_stack.ga_len;
! di = find_var_in_ht(ht, 0, iptr->isn_arg.string + 2, TRUE);
if (di == NULL)
store_var(iptr->isn_arg.string, STACK_TV_BOT(0));
else
{
clear_tv(&di->di_tv);
di->di_tv = *STACK_TV_BOT(0);
}
--- 1716,1729 ----
}
--ectx.ec_stack.ga_len;
! di = find_var_in_ht(ht, 0, name, TRUE);
if (di == NULL)
store_var(iptr->isn_arg.string, STACK_TV_BOT(0));
else
{
+ SOURCING_LNUM = iptr->isn_lnum;
+ if (var_check_permission(di, name) == FAIL)
+ goto on_error;
clear_tv(&di->di_tv);
di->di_tv = *STACK_TV_BOT(0);
}
*** ../vim-8.2.2192/src/testdir/test_vim9_func.vim 2020-12-22
18:56:52.055797690 +0100
--- src/testdir/test_vim9_func.vim 2020-12-22 20:32:58.685578131 +0100
***************
*** 1022,1027 ****
--- 1022,1038 ----
writefile(lines, 'Xcall_const.vim')
assert_fails('source Xcall_const.vim', 'E46:', '', 1, 'MyFunc')
delete('Xcall_const.vim')
+
+ lines =<< trim END
+ const g:Aconst = 77
+ def Change()
+ # comment
+ g:Aconst = 99
+ enddef
+ call Change()
+ unlet g:Aconst
+ END
+ CheckScriptFailure(lines, 'E741: Value is locked: Aconst', 2)
enddef
" Test that inside :function a Python function can be defined, :def is not
*** ../vim-8.2.2192/src/version.c 2020-12-22 19:05:29.454177553 +0100
--- src/version.c 2020-12-22 20:28:29.682522842 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 2193,
/**/
--
hundred-and-one symptoms of being an internet addict:
6. You refuse to go to a vacation spot with no electricity and no phone lines.
/// 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/202012221935.0BMJZw9u2656526%40masaka.moolenaar.net.