]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1917: Vim9: incorrect type inference with mkdir() v9.1.1917
authorYegappan Lakshmanan <yegappan@yahoo.com>
Sat, 15 Nov 2025 17:41:28 +0000 (17:41 +0000)
committerChristian Brabandt <cb@256bit.org>
Sat, 15 Nov 2025 17:41:28 +0000 (17:41 +0000)
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>
src/testdir/test_vim9_func.vim
src/version.c
src/vim9compile.c

index 85d672bd2ebdfb452be6a6820717c901456618a1..7cdf276e033e2b3bff6c1e1c517ae7e97fb3fb19 100644 (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()
index df95ec5067cf9981a89c2de36b593ecf960f910a..1a6093ac92f179a7f3db9c5a61cf00aef4448cb2 100644 (file)
@@ -729,6 +729,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1917,
 /**/
     1916,
 /**/
index bf3db28f7125d3b3d6ed1745bf76a185dc77f0a2..cab48bb8ae423623834d844ddb6087d15840fd0d 100644 (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;
 }