patch 9.1.1917: Vim9: incorrect type inference with mkdir()
Commit:
https://github.com/vim/vim/commit/a650485ed53cba4eb4d74e743a708fa51e2dd6db
Author: Yegappan Lakshmanan <[email protected]>
Date: Sat Nov 15 17:41:28 2025 +0000
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 <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 85d672bd2..7cdf276e0 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
@@ -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()
diff --git a/src/version.c b/src/version.c
index df95ec506..1a6093ac9 100644
--- a/src/version.c
+++ b/src/version.c
@@ -729,6 +729,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 1917,
/**/
1916,
/**/
diff --git a/src/vim9compile.c b/src/vim9compile.c
index bf3db28f7..cab48bb8a 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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;
}
--
--
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 visit
https://groups.google.com/d/msgid/vim_dev/E1vKKKf-004wzZ-Lg%40256bit.org.