Patch 9.0.0836

4 views
Skip to first unread message

Bram Moolenaar

unread,
Nov 5, 2022, 4:23:12 PM11/5/22
to vim...@googlegroups.com

Patch 9.0.0836
Problem: Wrong error when using extend() with funcref.
Solution: Better check the variable type. (closes #11468, closes #11455)
Files: src/dict.c, src/eval.c, src/testdir/test_functions.vim,
src/testdir/test_let.vim


*** ../vim-9.0.0835/src/dict.c 2022-11-02 13:30:37.530314524 +0000
--- src/dict.c 2022-11-05 20:12:02.784957936 +0000
***************
*** 352,358 ****
}

/*
! * Check for adding a function to g: or s:.
* If the name is wrong give an error message and return TRUE.
*/
int
--- 352,358 ----
}

/*
! * Check for adding a function to g: or s: (in Vim9 script) or l:.
* If the name is wrong give an error message and return TRUE.
*/
int
***************
*** 1105,1121 ****
{
--todo;
di1 = dict_find(d1, hi2->hi_key, -1);
! if (d1->dv_scope != 0)
! {
! // Disallow replacing a builtin function in l: and g:.
! // Check the key to be valid when adding to any scope.
! if (d1->dv_scope == VAR_DEF_SCOPE
! && HI2DI(hi2)->di_tv.v_type == VAR_FUNC
! && var_wrong_func_name(hi2->hi_key, di1 == NULL))
! break;
! if (!valid_varname(hi2->hi_key, -1, TRUE))
! break;
! }

if (type != NULL
&& check_typval_arg_type(type, &HI2DI(hi2)->di_tv,
--- 1105,1113 ----
{
--todo;
di1 = dict_find(d1, hi2->hi_key, -1);
! // Check the key to be valid when adding to any scope.
! if (d1->dv_scope != 0 && !valid_varname(hi2->hi_key, -1, TRUE))
! break;

if (type != NULL
&& check_typval_arg_type(type, &HI2DI(hi2)->di_tv,
***************
*** 1138,1143 ****
--- 1130,1136 ----
if (value_check_lock(di1->di_tv.v_lock, arg_errmsg, TRUE)
|| var_check_ro(di1->di_flags, arg_errmsg, TRUE))
break;
+ // Disallow replacing a builtin function.
if (dict_wrong_func_name(d1, &HI2DI(hi2)->di_tv, hi2->hi_key))
break;
clear_tv(&di1->di_tv);
*** ../vim-9.0.0835/src/eval.c 2022-11-02 13:30:37.530314524 +0000
--- src/eval.c 2022-11-05 20:12:02.784957936 +0000
***************
*** 1376,1382 ****
else
prevval = 0; // avoid compiler warning
wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
! && rettv->v_type == VAR_FUNC
&& var_wrong_func_name(key, lp->ll_di == NULL))
|| !valid_varname(key, -1, TRUE);
if (len != -1)
--- 1376,1383 ----
else
prevval = 0; // avoid compiler warning
wrong = (lp->ll_dict->dv_scope == VAR_DEF_SCOPE
! && (rettv->v_type == VAR_FUNC
! || rettv->v_type == VAR_PARTIAL)
&& var_wrong_func_name(key, lp->ll_di == NULL))
|| !valid_varname(key, -1, TRUE);
if (len != -1)
*** ../vim-9.0.0835/src/testdir/test_functions.vim 2022-10-10 16:08:12.478393959 +0100
--- src/testdir/test_functions.vim 2022-11-05 20:12:02.784957936 +0000
***************
*** 2938,2943 ****
--- 2938,2962 ----
let g:bar = 123
call extend(g:, #{bar: { -> "foo" }}, "keep")
call assert_fails('call extend(g:, #{bar: { -> "foo" }}, "force")', 'E704:')
+ unlet g:bar
+
+ call assert_fails('call extend(l:, #{foo: { -> "foo" }})', 'E704:')
+ let bar = 123
+ call extend(l:, #{bar: { -> "foo" }}, "keep")
+ call assert_fails('call extend(l:, #{bar: { -> "foo" }}, "force")', 'E704:')
+ unlet bar
+
+ call assert_fails('call extend(g:, #{foo: function("extend")})', 'E704:')
+ let g:bar = 123
+ call extend(g:, #{bar: function("extend")}, "keep")
+ call assert_fails('call extend(g:, #{bar: function("extend")}, "force")', 'E704:')
+ unlet g:bar
+
+ call assert_fails('call extend(l:, #{foo: function("extend")})', 'E704:')
+ let bar = 123
+ call extend(l:, #{bar: function("extend")}, "keep")
+ call assert_fails('call extend(l:, #{bar: function("extend")}, "force")', 'E704:')
+ unlet bar
endfunc

func Test_funcref_to_string()
*** ../vim-9.0.0835/src/testdir/test_let.vim 2022-09-29 21:01:52.206807939 +0100
--- src/testdir/test_let.vim 2022-11-05 20:12:02.784957936 +0000
***************
*** 316,321 ****
--- 316,322 ----
call assert_fails('let l += 2', 'E734:')
call assert_fails('let g:["a;b"] = 10', 'E461:')
call assert_fails('let g:.min = function("max")', 'E704:')
+ call assert_fails('let g:cos = "" | let g:.cos = {-> 42}', 'E704:')
if has('channel')
let ch = test_null_channel()
call assert_fails('let ch += 1', 'E734:')
*** ../vim-9.0.0835/src/version.c 2022-11-05 18:28:52.047344298 +0000
--- src/version.c 2022-11-05 20:19:43.977110919 +0000
***************
*** 697,698 ****
--- 697,700 ----
{ /* Add new patch number below this line */
+ /**/
+ 836,
/**/

--
Far out in the uncharted backwaters of the unfashionable end of the
Western Spiral arm of the Galaxy lies a small unregarded yellow sun.
Orbiting this at a distance of roughly ninety-eight million miles is an
utterly insignificant little blue-green planet whose ape-descended life
forms are so amazingly primitive that they still think digital watches
are a pretty neat idea ...
-- Douglas Adams, "The Hitchhiker's Guide to the Galaxy"

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
Reply all
Reply to author
Forward
0 new messages