To: vim_dev@googlegroups.com Subject: Patch 8.2.3997 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.3997 Problem: Vim9: not enough testing for extend() and map(). Solution: Add more test cases. Fix uncovered problems. Remove unused type fields. Files: src/structs.h, src/dict.c, src/list.c, src/vim9compile.c, src/testdir/test_vim9_builtin.vim, src/testdir/test_vim9_disassemble.vim *** ../vim-8.2.3996/src/structs.h 2022-01-04 15:16:57.875864890 +0000 --- src/structs.h 2022-01-04 15:44:23.565422244 +0000 *************** *** 1513,1519 **** } mat; } lv_u; type_T *lv_type; // current type, allocated by alloc_type() - type_T *lv_decl_type; // declared type, allocated by alloc_type() list_T *lv_copylist; // copied list used by deepcopy() list_T *lv_used_next; // next list in used lists list list_T *lv_used_prev; // previous list in used lists list --- 1513,1518 ---- *************** *** 1578,1584 **** int dv_copyID; // ID used by deepcopy() hashtab_T dv_hashtab; // hashtab that refers to the items type_T *dv_type; // current type, allocated by alloc_type() - type_T *dv_decl_type; // declared type, allocated by alloc_type() dict_T *dv_copydict; // copied dict used by deepcopy() dict_T *dv_used_next; // next dict in used dicts list dict_T *dv_used_prev; // previous dict in used dicts list --- 1577,1582 ---- *** ../vim-8.2.3996/src/dict.c 2022-01-04 15:16:57.875864890 +0000 --- src/dict.c 2022-01-04 15:44:30.101412328 +0000 *************** *** 109,116 **** hashtab_free_contents(&d->dv_hashtab); free_type(d->dv_type); d->dv_type = NULL; - free_type(d->dv_decl_type); - d->dv_decl_type = NULL; } /* --- 109,114 ---- *** ../vim-8.2.3996/src/list.c 2022-01-04 15:16:57.875864890 +0000 --- src/list.c 2022-01-04 15:43:54.561466188 +0000 *************** *** 271,277 **** l->lv_used_next->lv_used_prev = l->lv_used_prev; free_type(l->lv_type); - free_type(l->lv_decl_type); vim_free(l); } --- 271,276 ---- *************** *** 1026,1033 **** // The type will change. free_type(l->lv_type); l->lv_type = NULL; - free_type(l->lv_decl_type); - l->lv_decl_type = NULL; } else { --- 1025,1030 ---- *************** *** 1223,1229 **** if (copy != NULL) { copy->lv_type = alloc_type(orig->lv_type); - copy->lv_decl_type = alloc_type(orig->lv_decl_type); if (copyID != 0) { // Do this before adding the items, because one of the items may --- 1220,1225 ---- *** ../vim-8.2.3996/src/vim9compile.c 2022-01-04 15:16:57.879864882 +0000 --- src/vim9compile.c 2022-01-04 15:37:52.046009080 +0000 *************** *** 2279,2292 **** // ":const var": lock the value, but not referenced variables generate_LOCKCONST(cctx); ! if (is_decl ! && (lhs.lhs_type->tt_type == VAR_DICT || lhs.lhs_type->tt_type == VAR_LIST) && lhs.lhs_type->tt_member != NULL && lhs.lhs_type->tt_member != &t_unknown) // Set the type in the list or dict, so that it can be checked, ! // also in legacy script. Not for "list = val", then the ! // type of "val" is used. generate_SETTYPE(cctx, lhs.lhs_type); if (!skip_store && generate_store_lhs(cctx, &lhs, --- 2279,2290 ---- // ":const var": lock the value, but not referenced variables generate_LOCKCONST(cctx); ! if ((lhs.lhs_type->tt_type == VAR_DICT || lhs.lhs_type->tt_type == VAR_LIST) && lhs.lhs_type->tt_member != NULL && lhs.lhs_type->tt_member != &t_unknown) // Set the type in the list or dict, so that it can be checked, ! // also in legacy script. generate_SETTYPE(cctx, lhs.lhs_type); if (!skip_store && generate_store_lhs(cctx, &lhs, *** ../vim-8.2.3996/src/testdir/test_vim9_builtin.vim 2022-01-04 15:16:57.883864877 +0000 --- src/testdir/test_vim9_builtin.vim 2022-01-04 15:42:23.337604054 +0000 *************** *** 979,984 **** --- 979,988 ---- var res: list> extend(res, mapnew([1, 2], (_, v) => ({}))) assert_equal([{}, {}], res) + + var dany: dict = {a: 0} + dany->extend({b: 'x'}) + assert_equal({a: 0, b: 'x'}, dany) END CheckDefAndScriptSuccess(lines) *************** *** 2151,2159 **** CheckDefAndScriptFailure(['map(1, "1")'], ['E1013: Argument 1: type mismatch, expected list but got number', 'E1251: List, Dictionary, Blob or String required for argument 1']) # type of dict remains dict even when type of values changes ! var d: dict = {a: 0} ! d->map((k, v) => true) ! d->map((k, v) => 'x') enddef def Test_map_failure() --- 2155,2183 ---- CheckDefAndScriptFailure(['map(1, "1")'], ['E1013: Argument 1: type mismatch, expected list but got number', 'E1251: List, Dictionary, Blob or String required for argument 1']) # type of dict remains dict even when type of values changes ! # same for list ! var lines =<< trim END ! var d: dict = {a: 0} ! d->map((k, v) => true) ! d->map((k, v) => 'x') ! assert_equal({a: 'x'}, d) ! ! d = {a: 0} ! g:gd = d ! map(g:gd, (k, v) => true) ! assert_equal({a: true}, g:gd) ! ! var l: list = [0] ! l->map((k, v) => true) ! l->map((k, v) => 'x') ! assert_equal(['x'], l) ! ! l = [1] ! g:gl = l ! map(g:gl, (k, v) => true) ! assert_equal([true], g:gl) ! END ! CheckDefAndScriptSuccess(lines) enddef def Test_map_failure() *************** *** 2175,2180 **** --- 2199,2211 ---- CheckScriptFailure(lines, 'E1013:') au! BufReadPost delete('Xtmpfile') + + lines =<< trim END + var d: dict = {a: 1} + g:gd = d + map(g:gd, (k, v) => true) + END + CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got bool') enddef def Test_map_function_arg() *** ../vim-8.2.3996/src/testdir/test_vim9_disassemble.vim 2022-01-02 14:08:15.154169689 +0000 --- src/testdir/test_vim9_disassemble.vim 2022-01-04 15:53:45.984561081 +0000 *************** *** 455,460 **** --- 455,461 ---- '\d\+ CHECKTYPE string stack\[-1\] arg 2\_s*' .. '\d\+ STORE $1\_s*' .. '\d\+ SLICE 2\_s*' .. + '\d\+ SETTYPE list\_s*' .. '\d\+ STORE $2\_s*' .. '\d\+ RETURN void', res) *** ../vim-8.2.3996/src/version.c 2022-01-04 15:16:57.883864877 +0000 --- src/version.c 2022-01-04 15:22:48.903347948 +0000 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 3997, /**/ -- msdn.microsoft.com: ERROR_SUCCESS 0 (0x0) The operation completed successfully. I have always suspected that for Microsoft success is an error. /// 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 ///