To: vim_dev@googlegroups.com Subject: Patch 9.0.0840 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.0840 Problem: Cannot change a slice of a const list. (Takumi KAGIYAMA) Solution: Remove the const flag from the slice type. (closes #11490) Files: src/vim9expr.c, src/testdir/test_vim9_expr.vim *** ../vim-9.0.0839/src/vim9expr.c 2022-11-02 13:30:37.542314565 +0000 --- src/vim9expr.c 2022-11-06 17:32:55.621992985 +0000 *************** *** 185,190 **** --- 185,202 ---- // 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; + + // a copy is made, the composite is no longer "const" + if (typep->type_curr->tt_flags & TTFLAG_CONST) + { + type_T *type = copy_type(typep->type_curr, cctx->ctx_type_list); + + if (type != typep->type_curr) // did get a copy + { + type->tt_flags &= ~(TTFLAG_CONST | TTFLAG_STATIC); + typep->type_curr = type; + } + } } else { *** ../vim-9.0.0839/src/testdir/test_vim9_expr.vim 2022-10-17 13:13:28.705183595 +0100 --- src/testdir/test_vim9_expr.vim 2022-11-06 16:34:02.349470032 +0000 *************** *** 3132,3137 **** --- 3132,3149 ---- unlet g:testlist enddef + def s:GetList(): list + return ['a', 'b', 'z'] + enddef + + def Test_slice_const_list() + const list = GetList() + final sliced = list[0 : 1] + # OK to change the list after slicing, it is a copy now + add(sliced, 'Z') + assert_equal(['a', 'b', 'Z'], sliced) + enddef + def Test_expr9_const_any_index_slice() var lines =<< trim END vim9script *** ../vim-9.0.0839/src/version.c 2022-11-06 12:25:42.430836659 +0000 --- src/version.c 2022-11-06 16:09:36.893361279 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 840, /**/ -- How To Keep A Healthy Level Of Insanity: 10. Ask people what sex they are. Laugh hysterically after they answer. /// Bram Moolenaar -- Bram@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 ///