Patch 8.2.3091
Problem: Vim9: default argument expression cannot use previous argument
Solution: Correct argument index. (closes #8496)
Files: src/vim9compile.c, src/structs.h, src/testdir/test_vim9_func.vim
*** ../vim-8.2.3090/src/vim9compile.c 2021-07-03 13:36:27.871600408 +0200
--- src/vim9compile.c 2021-07-03 18:52:41.498144375 +0200
***************
*** 274,280 ****
if (len == 0)
return FAIL;
! for (idx = 0; idx < cctx->ctx_ufunc->uf_args.ga_len; ++idx)
{
char_u *arg = FUNCARG(cctx->ctx_ufunc, idx);
--- 274,280 ----
if (len == 0)
return FAIL;
! for (idx = 0; idx < cctx->ctx_ufunc->uf_args_visible; ++idx)
{
char_u *arg = FUNCARG(cctx->ctx_ufunc, idx);
***************
*** 9172,9178 ****
{
int count = ufunc->uf_def_args.ga_len;
int first_def_arg = ufunc->uf_args.ga_len - count;
- int uf_args_len = ufunc->uf_args.ga_len;
int i;
char_u *arg;
int off = STACK_FRAME_SIZE + (ufunc->uf_va_name != NULL ? 1 : 0);
--- 9172,9177 ----
***************
*** 9195,9206 ****
goto erret;
// Make sure later arguments are not found.
! ufunc->uf_args.ga_len = i;
arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i];
r = compile_expr0(&arg, &cctx);
- ufunc->uf_args.ga_len = uf_args_len;
if (r == FAIL)
goto erret;
--- 9194,9204 ----
goto erret;
// Make sure later arguments are not found.
! ufunc->uf_args_visible = arg_idx;
arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i];
r = compile_expr0(&arg, &cctx);
if (r == FAIL)
goto erret;
***************
*** 9230,9235 ****
--- 9228,9234 ----
if (did_set_arg_type)
set_function_type(ufunc);
}
+ ufunc->uf_args_visible = ufunc->uf_args.ga_len;
/*
* Loop over all the lines of the function and generate instructions.
*** ../vim-8.2.3090/src/structs.h 2021-06-27 13:03:55.986467776 +0200
--- src/structs.h 2021-07-03 18:50:34.062408333 +0200
***************
*** 1610,1615 ****
--- 1610,1617 ----
int uf_dfunc_idx; // only valid if uf_def_status is
UF_COMPILED
garray_T uf_args; // arguments, including optional arguments
garray_T uf_def_args; // default argument expressions
+ int uf_args_visible; // normally uf_args.ga_len, less when
+ // compiling default argument expression.
// for :def (for :function uf_ret_type is NULL)
type_T **uf_arg_types; // argument types (count == uf_args.ga_len)
*** ../vim-8.2.3090/src/testdir/test_vim9_func.vim 2021-06-26
22:22:35.770430468 +0200
--- src/testdir/test_vim9_func.vim 2021-07-03 18:54:50.437879244 +0200
***************
*** 452,457 ****
--- 452,463 ----
MyDefaultThird('->', 'xx', v:none)->assert_equal('->xxbb')
MyDefaultThird('->', v:none, 'yy')->assert_equal('->aayy')
MyDefaultThird('->', 'xx', 'yy')->assert_equal('->xxyy')
+
+ def DefArg(mandatory: any, optional = mandatory): string
+ return mandatory .. optional
+ enddef
+ DefArg(1234)->assert_equal('12341234')
+ DefArg("ok")->assert_equal('okok')
END
CheckDefAndScriptSuccess(lines)
*** ../vim-8.2.3090/src/version.c 2021-07-03 18:04:07.380374492 +0200
--- src/version.c 2021-07-03 18:40:01.823768227 +0200
***************
*** 757,758 ****
--- 757,760 ----
{ /* Add new patch number below this line */
+ /**/
+ 3091,
/**/
--
hundred-and-one symptoms of being an internet addict:
86. E-mail Deficiency Depression (EDD) forces you to e-mail yourself.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202107031657.163GvMoT2307644%40masaka.moolenaar.net.