diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim index 85d672bd2e..7cdf276e03 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 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 df95ec5067..1a6093ac92 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 bf3db28f71..cab48bb8ae 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; }