To: vim_dev@googlegroups.com Subject: Patch 8.2.2574 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2574 Problem: Vim9: crash when calling partial with wrong function. Solution: Check argument types of called function. (closes #7912) Files: src/vim9execute.c, src/testdir/test_vim9_func.vim *** ../vim-8.2.2573/src/vim9execute.c 2021-02-24 12:27:25.435824605 +0100 --- src/vim9execute.c 2021-03-06 19:23:45.959662715 +0100 *************** *** 797,803 **** --- 797,823 ---- } if (ufunc != NULL) + { + if (ufunc->uf_arg_types != NULL) + { + int i; + typval_T *argv = STACK_TV_BOT(0) - argcount; + + // The function can change at runtime, check that the argument + // types are correct. + for (i = 0; i < argcount; ++i) + { + type_T *type = i < ufunc->uf_args.ga_len + ? ufunc->uf_arg_types[i] : ufunc->uf_va_type; + + if (type != NULL && check_typval_arg_type(type, + &argv[i], i + 1) == FAIL) + return FAIL; + } + } + return call_ufunc(ufunc, NULL, argcount, ectx, iptr); + } return FAIL; } *** ../vim-8.2.2573/src/testdir/test_vim9_func.vim 2021-03-05 21:35:44.272045238 +0100 --- src/testdir/test_vim9_func.vim 2021-03-06 19:21:36.711874739 +0100 *************** *** 2367,2372 **** --- 2367,2396 ---- delete('XnestedDone') enddef + def Test_check_func_arg_types() + var lines =<< trim END + vim9script + def F1(x: string): string + return x + enddef + + def F2(x: number): number + return x + 1 + enddef + + def G(g: func): dict + return {f: g} + enddef + + def H(d: dict): string + return d.f('a') + enddef + END + + CheckScriptSuccess(lines + ['echo H(G(F1))']) + CheckScriptFailure(lines + ['echo H(G(F2))'], 'E1013:') + enddef + " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker *** ../vim-8.2.2573/src/version.c 2021-03-06 18:18:15.370336953 +0100 --- src/version.c 2021-03-06 19:23:00.739728997 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2574, /**/ -- To keep milk from turning sour: Keep it in the cow. /// 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 ///