summaryrefslogtreecommitdiffstats
path: root/src/dict.c
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-11-05 20:21:58 +0000
committerBram Moolenaar <Bram@vim.org>2022-11-05 20:21:58 +0000
commit91c75d18d9cdc32df57e648640de7476fbcb4d76 (patch)
tree9fa0460b1c499a272b85c5613b5c546f2ff37c93 /src/dict.c
parent845bbb72ed2da4b5fb2a503d91cfd6435df2f584 (diff)
patch 9.0.0836: wrong error when using extend() with funcrefv9.0.0836
Problem: Wrong error when using extend() with funcref. Solution: Better check the variable type. (closes #11468, closes #11455)
Diffstat (limited to 'src/dict.c')
-rw-r--r--src/dict.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/src/dict.c b/src/dict.c
index 82c31de515..c2f0fcc4d9 100644
--- a/src/dict.c
+++ b/src/dict.c
@@ -352,7 +352,7 @@ dict_copy(dict_T *orig, int deep, int top, int copyID)
}
/*
- * Check for adding a function to g: or s:.
+ * 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,17 +1105,9 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action, char *func_name)
{
--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;
- }
+ // 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,6 +1130,7 @@ dict_extend(dict_T *d1, dict_T *d2, char_u *action, char *func_name)
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);