To: vim_dev@googlegroups.com Subject: Patch 8.2.4287 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.4287 Problem: Cannot assign empty list with any list type to variable with specific list type. Solution: Use unknown list type for empty list if the specified type is any. Files: src/vim9type.c, src/testdir/test_vim9_assign.vim, src/testdir/test_vim9_func.vim *** ../vim-8.2.4286/src/vim9type.c 2022-02-02 20:01:21.957210955 +0000 --- src/vim9type.c 2022-02-03 12:17:58.507583981 +0000 *************** *** 344,350 **** list_T *l = tv->vval.v_list; listitem_T *li; ! if (l == NULL || (l->lv_first == NULL && l->lv_type == NULL)) return &t_list_empty; if ((flags & TVTT_DO_MEMBER) == 0) return &t_list_any; --- 344,354 ---- list_T *l = tv->vval.v_list; listitem_T *li; ! // An empty list has type list, unless the type was specified ! // and is not list. This matters when assigning to a variable ! // with a specific list type. ! if (l == NULL || (l->lv_first == NULL ! && (l->lv_type == NULL || l->lv_type->tt_member == &t_any))) return &t_list_empty; if ((flags & TVTT_DO_MEMBER) == 0) return &t_list_any; *** ../vim-8.2.4286/src/testdir/test_vim9_assign.vim 2022-02-02 20:01:21.961210953 +0000 --- src/testdir/test_vim9_assign.vim 2022-02-03 12:17:30.447655299 +0000 *************** *** 1249,1254 **** --- 1249,1263 ---- v9.CheckScriptSuccess(lines) enddef + def Test_assignment_empty_list() + var lines =<< trim END + var l2: list = [] + var l: list + l = l2 + END + v9.CheckDefAndScriptSuccess(lines) + enddef + def Test_assignment_vim9script() var lines =<< trim END vim9script *** ../vim-8.2.4286/src/testdir/test_vim9_func.vim 2022-01-30 18:40:40.535255817 +0000 --- src/testdir/test_vim9_func.vim 2022-02-03 12:32:40.081345004 +0000 *************** *** 3461,3471 **** enddef Foo() END lines[2] = 'var l: list' ! v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list> but got list', 2) ! lines[2] = 'var l: list = []' ! v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list> but got list', 2) lines[2] = 'var l: list = [11]' v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list> but got list', 2) --- 3461,3471 ---- enddef Foo() END + # "any" could be "dict", thus OK lines[2] = 'var l: list' ! v9.CheckScriptSuccess(lines) lines[2] = 'var l: list = []' ! v9.CheckScriptSuccess(lines) lines[2] = 'var l: list = [11]' v9.CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected list> but got list', 2) *** ../vim-8.2.4286/src/version.c 2022-02-02 20:01:21.961210953 +0000 --- src/version.c 2022-02-03 12:11:46.188530293 +0000 *************** *** 748,749 **** --- 748,751 ---- { /* Add new patch number below this line */ + /**/ + 4287, /**/ -- Engineers are widely recognized as superior marriage material: intelligent, dependable, employed, honest, and handy around the house. (Scott Adams - The Dilbert principle) /// 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 ///