To: vim_dev@googlegroups.com Subject: Patch 8.2.1261 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1261 Problem: Vim9: common type of function not tested. Solution: Add a test. Fix uncovered problems. Files: src/vim9compile.c, src/vim9execute.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.1260/src/vim9compile.c 2020-07-20 22:09:31.658114755 +0200 --- src/vim9compile.c 2020-07-21 20:22:02.379020286 +0200 *************** *** 1143,1155 **** RETURN_OK_IF_SKIP(cctx); ! if (type->tt_type == VAR_LIST) ! item_type = type->tt_member; ! else if (type->tt_type != VAR_ANY) { emsg(_(e_listreq)); return FAIL; } if ((isn = generate_instr(cctx, ISN_GETITEM)) == NULL) return FAIL; isn->isn_arg.number = index; --- 1143,1155 ---- RETURN_OK_IF_SKIP(cctx); ! if (type->tt_type != VAR_LIST) { + // cannot happen, caller has checked the type emsg(_(e_listreq)); return FAIL; } + item_type = type->tt_member; if ((isn = generate_instr(cctx, ISN_GETITEM)) == NULL) return FAIL; isn->isn_arg.number = index; *************** *** 4969,4974 **** --- 4969,4976 ---- if (var_count > 0 && is_decl) { + // TODO: should we allow this, and figure out type inference from list + // members? emsg(_("E1092: Cannot use a list for a declaration")); return NULL; } *** ../vim-8.2.1260/src/vim9execute.c 2020-07-19 20:48:56.182995168 +0200 --- src/vim9execute.c 2020-07-21 20:35:39.108585045 +0200 *************** *** 2470,2475 **** --- 2470,2476 ---- if (func_return(&ectx) == FAIL) // only fails when out of memory goto failed; + continue; on_error: if (trylevel == 0) *** ../vim-8.2.1260/src/testdir/test_vim9_expr.vim 2020-07-20 22:09:31.658114755 +0200 --- src/testdir/test_vim9_expr.vim 2020-07-21 20:54:35.466029333 +0200 *************** *** 3,8 **** --- 3,17 ---- source check.vim source vim9.vim + + let g:cond = v:false + def FuncOne(arg: number): string + return 'yes' + enddef + def FuncTwo(arg: number): number + return 123 + enddef + " test cond ? expr : expr def Test_expr1() assert_equal('one', true ? 'one' : 'two') *************** *** 43,48 **** --- 52,62 ---- let RetTwo: func(string): number = function('winnr') let RetThat: func = g:atrue ? RetOne : RetTwo assert_equal(function('len'), RetThat) + + let x = FuncOne + let y = FuncTwo + let Z = g:cond ? FuncOne : FuncTwo + assert_equal(123, Z(3)) enddef def Test_expr1_vimscript() *************** *** 88,93 **** --- 102,114 ---- call CheckDefFailure(["let x = 1 ? 'one': 'two'"], msg) call CheckDefFailure(["let x = 1 ? 'one' :'two'"], msg) call CheckDefFailure(["let x = 1 ? 'one':'two'"], msg) + + " missing argument detected even when common type is used + call CheckDefFailure([ + \ 'let x = FuncOne', + \ 'let y = FuncTwo', + \ 'let Z = g:cond ? FuncOne : FuncTwo', + \ 'Z()'], 'E119:') endfunc " TODO: define inside test function *** ../vim-8.2.1260/src/version.c 2020-07-21 19:44:44.046389568 +0200 --- src/version.c 2020-07-21 20:35:29.244615120 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1261, /**/ -- Q: What is a patch 22? A: A patch you need to include to make it possible to include patches. /// 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 ///