]> granicus.if.org Git - vim/commitdiff
patch 8.2.4313: Vim9: cannot change type of list after making a slice v8.2.4313
authorBram Moolenaar <Bram@vim.org>
Sun, 6 Feb 2022 18:36:53 +0000 (18:36 +0000)
committerBram Moolenaar <Bram@vim.org>
Sun, 6 Feb 2022 18:36:53 +0000 (18:36 +0000)
Problem:    Vim9: cannot change type of list after making a slice.
Solution:   Adjust the declared member type. (closes #9696)

src/testdir/test_vim9_builtin.vim
src/version.c
src/vim9expr.c

index ee32b3989c639365319a4714d6e4766fec85bb5e..3ad6e0e62d89fe9b026b03f0402616cddd67e724 100644 (file)
@@ -3626,6 +3626,7 @@ def Test_slice()
 
   var lds: list<dict<string>> = [{key: 'value'}]
   assert_equal(['val'], lds->slice(0, 1)->map((_, v) => 'val'))
+  assert_equal(['val'], lds[ : ]->map((_, v) => 'val'))
 
   assert_equal(0z1122334455, slice(0z001122334455, 1))
   assert_equal(0z112233, slice(0z001122334455, 1, 4))
index 825f12da3d7f644bcf40268ef0c203f009dbc82a..7dbefa49f82f782eb2d61c14f81e57196db19afe 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4313,
 /**/
     4312,
 /**/
index 146e136bda796fc4002145b836ee61b764439cf5..402803768befc5456e437c7e0485e97f42f1acc1 100644 (file)
@@ -182,6 +182,9 @@ compile_member(int is_slice, int *keeping_dict, cctx_T *cctx)
                     vartype == VAR_LIST ?  ISN_LISTSLICE : ISN_ANYSLICE,
                                                            2) == FAIL)
                return FAIL;
+           // a copy is made so the member type is no longer declared
+           if (typep->type_decl->tt_type == VAR_LIST)
+               typep->type_decl = &t_list_any;
        }
        else
        {