Patch 8.2.4973
Problem: Vim9: type error for list unpack mentions argument.
Solution: Mention variable. (close #10435)
Files: src/vim9.h, src/vim9execute.c, src/vim9instr.c,
src/proto/
vim9instr.pro, src/vim9compile.c,
src/testdir/test_vim9_script.vim,
src/testdir/test_vim9_disassemble.vim
*** ../vim-8.2.4972/src/vim9.h 2022-05-09 20:09:19.294641425 +0100
--- src/vim9.h 2022-05-17 15:59:25.272261459 +0100
***************
*** 296,301 ****
--- 296,302 ----
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
*** ../vim-8.2.4972/src/vim9execute.c 2022-05-09 20:09:19.294641425 +0100
--- src/vim9execute.c 2022-05-17 16:02:42.820123863 +0100
***************
*** 4652,4665 ****
--- 4652,4668 ----
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;
***************
*** 6114,6131 ****
case ISN_CHECKTYPE:
{
! 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",
pfx, current,
type_name(ct->ct_type, &tofree),
(int)ct->ct_off,
(int)ct->ct_arg_idx);
vim_free(tofree);
break;
--- 6117,6135 ----
case ISN_CHECKTYPE:
{
! 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] %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;
*** ../vim-8.2.4972/src/vim9instr.c 2022-05-10 13:24:17.640706898 +0100
--- src/vim9instr.c 2022-05-17 16:04:03.712146953 +0100
***************
*** 542,547 ****
--- 542,548 ----
cctx_T *cctx,
type_T *expected,
int offset,
+ int is_var,
int argidx)
{
isn_T *isn;
***************
*** 551,556 ****
--- 552,558 ----
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
***************
*** 1437,1443 ****
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);
return OK;
}
--- 1439,1445 ----
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, FALSE, 1);
return OK;
}
*** ../vim-8.2.4972/src/proto/
vim9instr.pro 2022-04-25 12:43:15.179819208 +0100
--- src/proto/
vim9instr.pro 2022-05-17 16:05:55.144160395 +0100
***************
*** 9,17 ****
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_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_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);
--- 9,18 ----
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 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);
***************
*** 62,68 ****
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);
--- 63,68 ----
*** ../vim-8.2.4972/src/vim9compile.c 2022-05-12 11:05:36.184621676 +0100
--- src/vim9compile.c 2022-05-17 16:04:50.712155019 +0100
***************
*** 412,418 ****
// 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);
return OK;
}
--- 412,419 ----
// 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_variable, where.wt_index);
return OK;
}
*** ../vim-8.2.4972/src/testdir/test_vim9_script.vim 2022-05-06 17:53:02.689329537 +0100
--- src/testdir/test_vim9_script.vim 2022-05-17 16:10:02.156132465 +0100
***************
*** 2302,2308 ****
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)
lines =<< trim END
var i = 0
--- 2302,2308 ----
echo k v
endfor
END
! 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
*** ../vim-8.2.4972/src/testdir/test_vim9_disassemble.vim 2022-05-06 13:14:43.797076608 +0100
--- src/testdir/test_vim9_disassemble.vim 2022-05-17 16:11:43.496104042 +0100
***************
*** 581,590 ****
'\d CHECKTYPE list<any> stack\[-1\]\_s*' ..
'\d CHECKLEN >= 2\_s*' ..
'\d\+ ITEM 0\_s*' ..
! '\d\+ CHECKTYPE string stack\[-1\] arg 1\_s*' ..
'\d\+ STORE $0\_s*' ..
'\d\+ ITEM 1\_s*' ..
! '\d\+ CHECKTYPE string stack\[-1\] arg 2\_s*' ..
'\d\+ STORE $1\_s*' ..
'\d\+ SLICE 2\_s*' ..
'\d\+ STORE $2\_s*' ..
--- 581,590 ----
'\d CHECKTYPE list<any> stack\[-1\]\_s*' ..
'\d CHECKLEN >= 2\_s*' ..
'\d\+ ITEM 0\_s*' ..
! '\d\+ CHECKTYPE string stack\[-1\] var 1\_s*' ..
'\d\+ STORE $0\_s*' ..
'\d\+ ITEM 1\_s*' ..
! '\d\+ CHECKTYPE string stack\[-1\] var 2\_s*' ..
'\d\+ STORE $1\_s*' ..
'\d\+ SLICE 2\_s*' ..
'\d\+ STORE $2\_s*' ..
*** ../vim-8.2.4972/src/version.c 2022-05-17 15:03:29.706610336 +0100
--- src/version.c 2022-05-17 16:12:11.520094799 +0100
***************
*** 748,749 ****
--- 748,751 ----
{ /* Add new patch number below this line */
+ /**/
+ 4973,
/**/
--
If evolution theories are correct, humans will soon grow a third
hand for operating the mouse.
/// Bram Moolenaar -- Br...@Moolenaar.net --
http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features --
http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims --
http://ICCF-Holland.org ///