Problem: Vim9: type error for list unpack mentions argument.
Solution: Mention variable. (close #10435)
int generate_two_op(cctx_T *cctx, char_u *op);
int check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2);
int generate_COMPARE(cctx_T *cctx, exprtype_T exprtype, int ic);
+int generate_CONCAT(cctx_T *cctx, int count);
int generate_2BOOL(cctx_T *cctx, int invert, int offset);
int generate_COND2BOOL(cctx_T *cctx);
-int generate_TYPECHECK(cctx_T *cctx, type_T *expected, int offset, int argidx);
+int generate_TYPECHECK(cctx_T *cctx, type_T *expected, int offset, int is_var, int argidx);
int generate_SETTYPE(cctx_T *cctx, type_T *expected);
int generate_tv_PUSH(cctx_T *cctx, typval_T *tv);
int generate_PUSHNR(cctx_T *cctx, varnumber_T number);
int generate_EXECCONCAT(cctx_T *cctx, int count);
int generate_RANGE(cctx_T *cctx, char_u *range);
int generate_UNPACK(cctx_T *cctx, int var_count, int semicolon);
-int generate_CONCAT(cctx_T *cctx, int count);
int generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod);
int generate_undo_cmdmods(cctx_T *cctx);
int generate_store_var(cctx_T *cctx, assign_dest_T dest, int opt_flags, int vimvaridx, int scriptvar_idx, int scriptvar_sid, type_T *type, char_u *name);
'\d CHECKTYPE list<any> stack\[-1\]\_s*' ..
'\d CHECKLEN >= 2\_s*' ..
'\d\+ ITEM 0\_s*' ..
- '\d\+ CHECKTYPE string stack\[-1\] arg 1\_s*' ..
+ '\d\+ CHECKTYPE string stack\[-1\] var 1\_s*' ..
'\d\+ STORE $0\_s*' ..
'\d\+ ITEM 1\_s*' ..
- '\d\+ CHECKTYPE string stack\[-1\] arg 2\_s*' ..
+ '\d\+ CHECKTYPE string stack\[-1\] var 2\_s*' ..
'\d\+ STORE $1\_s*' ..
'\d\+ SLICE 2\_s*' ..
'\d\+ STORE $2\_s*' ..
echo k v
endfor
END
- v9.CheckDefExecAndScriptFailure(lines, ['E1013: Argument 1: type mismatch, expected job but got string', 'E1012: Type mismatch; expected job but got string'], 2)
+ v9.CheckDefExecAndScriptFailure(lines, ['E1163: Variable 1: type mismatch, expected job but got string', 'E1012: Type mismatch; expected job but got string'], 2)
lines =<< trim END
var i = 0
static int included_patches[] =
{ /* Add new patch number below this line */
+/**/
+ 4973,
/**/
4972,
/**/
type_T *ct_type;
int8_T ct_off; // offset in stack, -1 is bottom
int8_T ct_arg_idx; // argument index or zero
+ int8_T ct_is_var; // when TRUE checking variable instead of arg
} checktype_T;
// arguments to ISN_STORENR
// If the actual type can be the expected type add a runtime check.
if (!actual_is_const && ret == MAYBE && use_typecheck(actual, expected))
{
- generate_TYPECHECK(cctx, expected, offset, where.wt_index);
+ generate_TYPECHECK(cctx, expected, offset,
+ where.wt_variable, where.wt_index);
return OK;
}
case ISN_CHECKTYPE:
{
checktype_T *ct = &iptr->isn_arg.type;
+ int save_wt_variable = ectx->ec_where.wt_variable;
tv = STACK_TV_BOT((int)ct->ct_off);
SOURCING_LNUM = iptr->isn_lnum;
if (!ectx->ec_where.wt_variable)
ectx->ec_where.wt_index = ct->ct_arg_idx;
+ ectx->ec_where.wt_variable = ct->ct_is_var;
if (check_typval_type(ct->ct_type, tv, ectx->ec_where)
== FAIL)
goto on_error;
+ ectx->ec_where.wt_variable = save_wt_variable;
if (!ectx->ec_where.wt_variable)
ectx->ec_where.wt_index = 0;
case ISN_CHECKTYPE:
{
- checktype_T *ct = &iptr->isn_arg.type;
- char *tofree;
+ checktype_T *ct = &iptr->isn_arg.type;
+ char *tofree;
if (ct->ct_arg_idx == 0)
smsg("%s%4d CHECKTYPE %s stack[%d]", pfx, current,
type_name(ct->ct_type, &tofree),
(int)ct->ct_off);
else
- smsg("%s%4d CHECKTYPE %s stack[%d] arg %d",
+ smsg("%s%4d CHECKTYPE %s stack[%d] %s %d",
pfx, current,
type_name(ct->ct_type, &tofree),
(int)ct->ct_off,
+ ct->ct_is_var ? "var": "arg",
(int)ct->ct_arg_idx);
vim_free(tofree);
break;
cctx_T *cctx,
type_T *expected,
int offset,
+ int is_var,
int argidx)
{
isn_T *isn;
return FAIL;
isn->isn_arg.type.ct_type = alloc_type(expected);
isn->isn_arg.type.ct_off = (int8_T)offset;
+ isn->isn_arg.type.ct_is_var = is_var;
isn->isn_arg.type.ct_arg_idx = (int8_T)argidx;
// type becomes expected
if (maptype != NULL && maptype[0].type_decl->tt_member != NULL
&& maptype[0].type_decl->tt_member != &t_any)
// Check that map() didn't change the item types.
- generate_TYPECHECK(cctx, maptype[0].type_decl, -1, 1);
+ generate_TYPECHECK(cctx, maptype[0].type_decl, -1, FALSE, 1);
return OK;
}