To: vim_dev@googlegroups.com Subject: Patch 8.2.1534 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.1534 Problem: Vim9: type error for argument type is not at call position. Solution: Set the context and stack after checking the arguments. (issue #6785) Files: src/userfunc.c, src/vim9execute.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.1533/src/userfunc.c 2020-08-21 22:36:43.662719906 +0200 --- src/userfunc.c 2020-08-28 17:12:55.736827878 +0200 *************** *** 1314,1330 **** if (fp->uf_def_status != UF_NOT_COMPILED) { - estack_push_ufunc(fp, 1); - save_current_sctx = current_sctx; - current_sctx = fp->uf_script_ctx; - // Execute the function, possibly compiling it first. call_def_function(fp, argcount, argvars, funcexe->partial, rettv); --depth; current_funccal = fc->caller; - - estack_pop(); - current_sctx = save_current_sctx; free_funccal(fc); return; } --- 1314,1323 ---- *** ../vim-8.2.1533/src/vim9execute.c 2020-08-23 16:29:07.737130996 +0200 --- src/vim9execute.c 2020-08-28 17:18:41.535945652 +0200 *************** *** 726,732 **** int idx; int ret = FAIL; int defcount = ufunc->uf_args.ga_len - argc; ! int save_sc_version = current_sctx.sc_version; int breakcheck_count = 0; int called_emsg_before = called_emsg; --- 726,732 ---- int idx; int ret = FAIL; int defcount = ufunc->uf_args.ga_len - argc; ! sctx_T save_current_sctx = current_sctx; int breakcheck_count = 0; int called_emsg_before = called_emsg; *************** *** 867,873 **** --- 867,876 ---- ectx.ec_instr = dfunc->df_instr; } + // Following errors are in the function, not the caller. // Commands behave like vim9script. + estack_push_ufunc(ufunc, 1); + current_sctx = ufunc->uf_script_ctx; current_sctx.sc_version = SCRIPT_VERSION_VIM9; // Decide where to start execution, handles optional arguments. *************** *** 2614,2622 **** // When failed need to unwind the call stack. while (ectx.ec_frame_idx != initial_frame_idx) func_return(&ectx); - failed_early: - current_sctx.sc_version = save_sc_version; // Free all local variables, but not arguments. for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx) clear_tv(STACK_TV(idx)); --- 2617,2627 ---- // When failed need to unwind the call stack. while (ectx.ec_frame_idx != initial_frame_idx) func_return(&ectx); + estack_pop(); + current_sctx = save_current_sctx; + + failed_early: // Free all local variables, but not arguments. for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx) clear_tv(STACK_TV(idx)); *** ../vim-8.2.1533/src/testdir/test_vim9_func.vim 2020-08-28 16:39:28.258176214 +0200 --- src/testdir/test_vim9_func.vim 2020-08-28 17:17:19.732159227 +0200 *************** *** 223,228 **** --- 223,237 ---- call CheckDefFailure(['TakesOneArg(11, 22)'], 'E118:') call CheckDefFailure(['bufnr(xxx)'], 'E1001:') call CheckScriptFailure(['def Func(Ref: func(s: string))'], 'E475:') + + let lines =<< trim END + vim9script + def Func(s: string) + echo s + enddef + Func([]) + END + call CheckScriptFailure(lines, 'E1012: type mismatch, expected string but got list', 5) enddef " Default arg and varargs *** ../vim-8.2.1533/src/version.c 2020-08-28 16:39:28.258176214 +0200 --- src/version.c 2020-08-28 17:07:38.101577328 +0200 *************** *** 756,757 **** --- 756,759 ---- { /* Add new patch number below this line */ + /**/ + 1534, /**/ -- GALAHAD hurries to the door and pushes through it. As he leaves the room we CUT TO the reverse to show that he is now in a room full of bathing and romping GIRLIES, all innocent, wide-eyed and beautiful. They smile enchantingly at him as he tries to keep walking without being diverted by the lovely sights assaulting his eyeballs. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// 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 ///