summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-02-06 15:49:35 +0000
committerBram Moolenaar <Bram@vim.org>2022-02-06 15:49:35 +0000
commit2626d6a71ca616bd91d4ee2c27bd76a78a00d412 (patch)
treec95b2cbe59caeb449cd551f22e286f906d69a905
parentfe1bfc9b267fffedac6b5224d7aa6cc5d9d15f64 (diff)
patch 8.2.4310: Vim9: constant list and dict get a declaration typev8.2.4310
Problem: Vim9: constant list and dict get a declaration type other than "any". Solution: A constant list and dict have a declared member type "any". (closes #9701)
-rw-r--r--src/proto/vim9type.pro2
-rw-r--r--src/testdir/test_vim9_builtin.vim5
-rw-r--r--src/version.c2
-rw-r--r--src/vim9instr.c12
-rw-r--r--src/vim9type.c9
5 files changed, 12 insertions, 18 deletions
diff --git a/src/proto/vim9type.pro b/src/proto/vim9type.pro
index fb3cb8d145..aaa1a71eb2 100644
--- a/src/proto/vim9type.pro
+++ b/src/proto/vim9type.pro
@@ -27,7 +27,7 @@ int push_type_stack2(cctx_T *cctx, type_T *type, type_T *decl_type);
void set_type_on_stack(cctx_T *cctx, type_T *type, int offset);
type_T *get_type_on_stack(cctx_T *cctx, int offset);
type_T *get_decl_type_on_stack(cctx_T *cctx, int offset);
-type_T *get_member_type_from_stack(int count, int skip, type_T **decl_type, cctx_T *cctx);
+type_T *get_member_type_from_stack(int count, int skip, cctx_T *cctx);
char *vartype_name(vartype_T type);
char *type_name(type_T *type, char **tofree);
void f_typename(typval_T *argvars, typval_T *rettv);
diff --git a/src/testdir/test_vim9_builtin.vim b/src/testdir/test_vim9_builtin.vim
index 557ddf2190..ee32b3989c 100644
--- a/src/testdir/test_vim9_builtin.vim
+++ b/src/testdir/test_vim9_builtin.vim
@@ -2237,6 +2237,11 @@ def Test_map()
g:gl = l
map(g:gl, (k, v) => true)
assert_equal([true], g:gl)
+
+ assert_equal(['x'], [[1, 2]]->map((_, v) => 'x'))
+ assert_equal(['x'], [{a: 0}]->map((_, v) => 'x'))
+ assert_equal({a: 'x'}, {a: [1, 2]}->map((_, v) => 'x'))
+ assert_equal({a: 'x'}, {a: {b: 2}}->map((_, v) => 'x'))
END
v9.CheckDefAndScriptSuccess(lines)
enddef
diff --git a/src/version.c b/src/version.c
index 37d653d3a5..20bc28ab46 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4310,
+/**/
4309,
/**/
4308,
diff --git a/src/vim9instr.c b/src/vim9instr.c
index 60963a3c9b..cf26650d17 100644
--- a/src/vim9instr.c
+++ b/src/vim9instr.c
@@ -1067,7 +1067,6 @@ generate_NEWLIST(cctx_T *cctx, int count)
{
isn_T *isn;
type_T *member_type;
- type_T *decl_member_type;
type_T *type;
type_T *decl_type;
@@ -1078,10 +1077,9 @@ generate_NEWLIST(cctx_T *cctx, int count)
// Get the member type and the declared member type from all the items on
// the stack.
- member_type = get_member_type_from_stack(count, 1,
- &decl_member_type, cctx);
+ member_type = get_member_type_from_stack(count, 1, cctx);
type = get_list_type(member_type, cctx->ctx_type_list);
- decl_type = get_list_type(decl_member_type, cctx->ctx_type_list);
+ decl_type = get_list_type(&t_any, cctx->ctx_type_list);
// drop the value types
cctx->ctx_type_stack.ga_len -= count;
@@ -1098,7 +1096,6 @@ generate_NEWDICT(cctx_T *cctx, int count)
{
isn_T *isn;
type_T *member_type;
- type_T *decl_member_type;
type_T *type;
type_T *decl_type;
@@ -1107,10 +1104,9 @@ generate_NEWDICT(cctx_T *cctx, int count)
return FAIL;
isn->isn_arg.number = count;
- member_type = get_member_type_from_stack(count, 2,
- &decl_member_type, cctx);
+ member_type = get_member_type_from_stack(count, 2, cctx);
type = get_dict_type(member_type, cctx->ctx_type_list);
- decl_type = get_dict_type(decl_member_type, cctx->ctx_type_list);
+ decl_type = get_dict_type(&t_any, cctx->ctx_type_list);
// drop the key and value types
cctx->ctx_type_stack.ga_len -= 2 * count;
diff --git a/src/vim9type.c b/src/vim9type.c
index f72698cb9d..62be6ac619 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -1359,7 +1359,6 @@ get_decl_type_on_stack(cctx_T *cctx, int offset)
get_member_type_from_stack(
int count,
int skip,
- type_T **decl_type,
cctx_T *cctx)
{
garray_T *stack = &cctx->ctx_type_stack;
@@ -1367,32 +1366,24 @@ get_member_type_from_stack(
garray_T *type_gap = cctx->ctx_type_list;
int i;
type_T *result;
- type_T *decl_result;
type_T *type;
// Use "unknown" for an empty list or dict.
if (count == 0)
- {
- *decl_type = &t_unknown;
return &t_unknown;
- }
// Use the first value type for the list member type, then find the common
// type from following items.
typep = ((type2_T *)stack->ga_data) + stack->ga_len;
result = (typep -(count * skip) + skip - 1)->type_curr;
- decl_result = (typep -(count * skip) + skip - 1)->type_decl;
for (i = 1; i < count; ++i)
{
if (result == &t_any)
break; // won't get more common
type = (typep -((count - i) * skip) + skip - 1)->type_curr;
common_type(type, result, &result, type_gap);
- type = (typep -((count - i) * skip) + skip - 1)->type_decl;
- common_type(type, decl_result, &decl_result, type_gap);
}
- *decl_type = decl_result;
return result;
}