0
0
mirror of https://github.com/vim/vim.git synced 2025-11-16 23:24:03 -05:00

patch 9.1.1917: Vim9: incorrect type inference with mkdir()

Problem:  Vim9: incorrect type inference with mkdir()
          (dezza)
Solution: Before compiling a RHS expression in an assignment, save the
          new local variable contents (Yegappan Lakshmanan)

fixes: #18751
closes: #18751

Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Yegappan Lakshmanan
2025-11-15 17:41:28 +00:00
committed by Christian Brabandt
parent 61b73b89a3
commit a650485ed5
3 changed files with 33 additions and 0 deletions

View File

@@ -4771,6 +4771,20 @@ def Test_call_modified_import_func()
v9.CheckScriptSuccess(lines)
enddef
" Test for assigning the return value of mkdir() to a new local variable.
" This used to result in the "E1012: Type mismatch; expected list<any> but
" got number" error message.
def Test_assign_mkdir_ret_value()
var lines =<< trim END
vim9script
def Fn()
var ret: number = mkdir('./foo/bar/baz', 'p')
enddef
defcompile
END
v9.CheckScriptSuccess(lines)
enddef
" The following messes up syntax highlight, keep near the end.
if has('python3')
def Test_python3_command()

View File

@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1917,
/**/
1916,
/**/

View File

@@ -3170,6 +3170,8 @@ compile_assign_single_eval_expr(cctx_T *cctx, cac_T *cac)
int ret = OK;
char_u *whitep;
lhs_T *lhs = &cac->cac_lhs;
lvar_T *lvp;
lvar_T save_lhs_lvar;
// Compile the expression.
if (cac->cac_incdec)
@@ -3178,7 +3180,14 @@ compile_assign_single_eval_expr(cctx_T *cctx, cac_T *cac)
// Temporarily hide the new local variable here, it is
// not available to this expression.
if (lhs->lhs_new_local)
{
--cctx->ctx_locals.ga_len;
// Save the local variable value (compiling the RHS expression may
// create new local variables).
lvp = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len;
save_lhs_lvar = *lvp;
}
whitep = cac->cac_op + cac->cac_oplen;
if (may_get_next_line_error(whitep, &cac->cac_nextc, cctx) == FAIL)
@@ -3190,7 +3199,15 @@ compile_assign_single_eval_expr(cctx_T *cctx, cac_T *cac)
ret = compile_expr0_ext(&cac->cac_nextc, cctx, &cac->cac_is_const);
if (lhs->lhs_new_local)
{
// Restore the local variable value. Update lhs_lvar as the index of
// the local variable might have changed.
lvp = ((lvar_T *)cctx->ctx_locals.ga_data) + cctx->ctx_locals.ga_len;
*lvp = save_lhs_lvar;
lhs->lhs_lvar = lvp;
++cctx->ctx_locals.ga_len;
}
return ret;
}