To: vim_dev@googlegroups.com Subject: Patch 8.2.2145 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2145 Problem: Vim9: concatenating lists does not adjust type of result. Solution: When list member types differ use "any" member type. (closes #7473) Files: src/vim9compile.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.2144/src/vim9compile.c 2020-12-13 21:26:51.565418479 +0100 --- src/vim9compile.c 2020-12-15 21:28:27.896083780 +0100 *************** *** 538,551 **** type_T *type1, type_T *type2) { ! isn_T *isn = generate_instr_drop(cctx, ! vartype == VAR_NUMBER ? ISN_OPNR ! : vartype == VAR_LIST ? ISN_ADDLIST ! : vartype == VAR_BLOB ? ISN_ADDBLOB #ifdef FEAT_FLOAT ! : vartype == VAR_FLOAT ? ISN_OPFLOAT #endif ! : ISN_OPANY, 1); if (vartype != VAR_LIST && vartype != VAR_BLOB && type1->tt_type != VAR_ANY --- 538,552 ---- type_T *type1, type_T *type2) { ! garray_T *stack = &cctx->ctx_type_stack; ! isn_T *isn = generate_instr_drop(cctx, ! vartype == VAR_NUMBER ? ISN_OPNR ! : vartype == VAR_LIST ? ISN_ADDLIST ! : vartype == VAR_BLOB ? ISN_ADDBLOB #ifdef FEAT_FLOAT ! : vartype == VAR_FLOAT ? ISN_OPFLOAT #endif ! : ISN_OPANY, 1); if (vartype != VAR_LIST && vartype != VAR_BLOB && type1->tt_type != VAR_ANY *************** *** 556,561 **** --- 557,570 ---- if (isn != NULL) isn->isn_arg.op.op_type = EXPR_ADD; + + // When concatenating two lists with different member types the member type + // becomes "any". + if (vartype == VAR_LIST + && type1->tt_type == VAR_LIST && type2->tt_type == VAR_LIST + && type1->tt_member != type2->tt_member) + (((type_T **)stack->ga_data)[stack->ga_len - 1]) = &t_list_any; + return isn == NULL ? FAIL : OK; } *************** *** 7172,7177 **** --- 7181,7187 ---- // Either no range or a number. // "errormsg" will not be set because the range is ADDR_LINES. if (parse_cmd_address(eap, &errormsg, FALSE) == FAIL) + // cannot happen return NULL; if (eap->addr_count == 0) lnum = -1; *** ../vim-8.2.2144/src/testdir/test_vim9_expr.vim 2020-12-09 12:41:44.934219841 +0100 --- src/testdir/test_vim9_expr.vim 2020-12-15 21:15:36.018534668 +0100 *************** *** 1317,1322 **** --- 1317,1339 ---- call CheckDefFailure(["var x = 'a' .. test_null_channel()"], 'E1105:', 1) endfunc + def Test_expr5_list_add() + # concatenating two lists with same member types is OK + var d = {} + for i in ['a'] + ['b'] + d = {[i]: 0} + endfor + + # concatenating two lists with different member types results in "any" + var lines =<< trim END + var d = {} + for i in ['a'] + [0] + d = {[i]: 0} + endfor + END + CheckDefExecFailure(lines, 'E1012:') + enddef + " test multiply, divide, modulo def Test_expr6() var lines =<< trim END *** ../vim-8.2.2144/src/version.c 2020-12-14 18:31:24.062840347 +0100 --- src/version.c 2020-12-15 21:28:37.372053306 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2145, /**/ -- The problem with political jokes is that they get elected. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///