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()
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)
// 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)
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;
}