summaryrefslogtreecommitdiffstats
path: root/src/evalfunc.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-01-27 16:36:29 +0000
committerBram Moolenaar <Bram@vim.org>2022-01-27 16:36:29 +0000
commit35c807df1f5774f09612d756ddc3cd5c44eacaca (patch)
tree5f591a6dd01925947e2e3c6e9c6e5a5ae8c3dc77 /src/evalfunc.c
parent94373c48e7e438e5b924b34ce820e9b2eb9f810c (diff)
patch 8.2.4231: Vim9: map() gives type error when type was not declaredv8.2.4231
Problem: Vim9: map() gives type error when type was not declared. Solution: Only check the type when it was declared, like extend() does. (closes #9635)
Diffstat (limited to 'src/evalfunc.c')
-rw-r--r--src/evalfunc.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 627ebb0b08..411d332997 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -530,21 +530,30 @@ arg_map_func(type_T *type, type_T *decl_type UNUSED, argcontext_T *context)
if (type->tt_type == VAR_FUNC)
{
- if (type->tt_member != &t_any
- && type->tt_member != &t_unknown)
+ if (type->tt_member != &t_any && type->tt_member != &t_unknown)
{
type_T *expected = NULL;
if (context->arg_types[0].type_curr->tt_type == VAR_LIST
|| context->arg_types[0].type_curr->tt_type == VAR_DICT)
- expected = context->arg_types[0].type_curr->tt_member;
+ {
+ // Use the declared type, so that an error is given if a
+ // declared list changes type, but not if a constant list
+ // changes type.
+ if (context->arg_types[0].type_decl->tt_type == VAR_LIST
+ || context->arg_types[0].type_decl->tt_type == VAR_DICT)
+ expected = context->arg_types[0].type_decl->tt_member;
+ else
+ expected = context->arg_types[0].type_curr->tt_member;
+ }
else if (context->arg_types[0].type_curr->tt_type == VAR_STRING)
expected = &t_string;
else if (context->arg_types[0].type_curr->tt_type == VAR_BLOB)
expected = &t_number;
if (expected != NULL)
{
- type_T t_func_exp = {VAR_FUNC, -1, 0, TTFLAG_STATIC, NULL, NULL};
+ type_T t_func_exp = {VAR_FUNC, -1, 0, TTFLAG_STATIC,
+ NULL, NULL};
t_func_exp.tt_member = expected;
return check_arg_type(&t_func_exp, type, context);