To: vim_dev@googlegroups.com Subject: Patch 8.2.4304 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4304 Problem: Vim9: slice() makes a copy but doesn't change the type. Solution: Change the declared type like copy(). (closes #9696) Files: src/evalfunc.c, src/testdir/test_vim9_builtin.vim *** ../vim-8.2.4303/src/evalfunc.c 2022-02-05 18:12:30.300504904 +0000 --- src/evalfunc.c 2022-02-05 19:20:19.430879748 +0000 *************** *** 1169,1174 **** --- 1169,1195 ---- return &t_void; } static type_T * + ret_slice(int argcount, + type2_T *argtypes, + type_T **decl_type) + { + if (argcount > 0) + { + if (argtypes[0].type_decl != NULL) + { + switch (argtypes[0].type_decl->tt_type) + { + case VAR_STRING: *decl_type = &t_string; break; + case VAR_BLOB: *decl_type = &t_blob; break; + case VAR_LIST: *decl_type = &t_list_any; break; + default: break; + } + } + return argtypes[0].type_curr; + } + return &t_void; + } + static type_T * ret_copy(int argcount, type2_T *argtypes, type_T **decl_type) *************** *** 2292,2298 **** {"sinh", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_sinh)}, {"slice", 2, 3, FEARG_1, arg23_slice, ! ret_first_arg, f_slice}, {"sort", 1, 3, FEARG_1, arg13_sortuniq, ret_first_arg, f_sort}, {"sound_clear", 0, 0, 0, NULL, --- 2313,2319 ---- {"sinh", 1, 1, FEARG_1, arg1_float_or_nr, ret_float, FLOAT_FUNC(f_sinh)}, {"slice", 2, 3, FEARG_1, arg23_slice, ! ret_slice, f_slice}, {"sort", 1, 3, FEARG_1, arg13_sortuniq, ret_first_arg, f_sort}, {"sound_clear", 0, 0, 0, NULL, *** ../vim-8.2.4303/src/testdir/test_vim9_builtin.vim 2022-02-05 18:12:30.300504904 +0000 --- src/testdir/test_vim9_builtin.vim 2022-02-05 19:19:37.834992047 +0000 *************** *** 3619,3624 **** --- 3619,3627 ---- assert_equal([], slice(range(6), 1, -5)) assert_equal([], slice(range(6), 1, -6)) + var lds: list> = [{key: 'value'}] + assert_equal(['val'], lds->slice(0, 1)->map((_, v) => 'val')) + assert_equal(0z1122334455, slice(0z001122334455, 1)) assert_equal(0z112233, slice(0z001122334455, 1, 4)) assert_equal(0z11223344, slice(0z001122334455, 1, -1)) *** ../vim-8.2.4303/src/version.c 2022-02-05 18:53:02.585494018 +0000 --- src/version.c 2022-02-05 19:10:55.264258518 +0000 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4304, /**/ -- hundred-and-one symptoms of being an internet addict: 4. Your eyeglasses have a web site burned in on them. /// 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 ///