Skip to content

Commit bd3a9d2

Browse files
committed
patch 8.2.4973: Vim9: type error for list unpack mentions argument
Problem: Vim9: type error for list unpack mentions argument. Solution: Mention variable. (close #10435)
1 parent 1ff9c44 commit bd3a9d2

File tree

8 files changed

+20
-10
lines changed

8 files changed

+20
-10
lines changed

src/proto/vim9instr.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ vartype_T operator_type(type_T *type1, type_T *type2);
99
int generate_two_op(cctx_T *cctx, char_u *op);
1010
int check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2);
1111
int generate_COMPARE(cctx_T *cctx, exprtype_T exprtype, int ic);
12+
int generate_CONCAT(cctx_T *cctx, int count);
1213
int generate_2BOOL(cctx_T *cctx, int invert, int offset);
1314
int generate_COND2BOOL(cctx_T *cctx);
14-
int generate_TYPECHECK(cctx_T *cctx, type_T *expected, int offset, int argidx);
15+
int generate_TYPECHECK(cctx_T *cctx, type_T *expected, int offset, int is_var, int argidx);
1516
int generate_SETTYPE(cctx_T *cctx, type_T *expected);
1617
int generate_tv_PUSH(cctx_T *cctx, typval_T *tv);
1718
int generate_PUSHNR(cctx_T *cctx, varnumber_T number);
@@ -62,7 +63,6 @@ int generate_LEGACY_EVAL(cctx_T *cctx, char_u *line);
6263
int generate_EXECCONCAT(cctx_T *cctx, int count);
6364
int generate_RANGE(cctx_T *cctx, char_u *range);
6465
int generate_UNPACK(cctx_T *cctx, int var_count, int semicolon);
65-
int generate_CONCAT(cctx_T *cctx, int count);
6666
int generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod);
6767
int generate_undo_cmdmods(cctx_T *cctx);
6868
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);

src/testdir/test_vim9_disassemble.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,10 @@ def Test_disassemble_list_assign()
581581
'\d CHECKTYPE list<any> stack\[-1\]\_s*' ..
582582
'\d CHECKLEN >= 2\_s*' ..
583583
'\d\+ ITEM 0\_s*' ..
584-
'\d\+ CHECKTYPE string stack\[-1\] arg 1\_s*' ..
584+
'\d\+ CHECKTYPE string stack\[-1\] var 1\_s*' ..
585585
'\d\+ STORE $0\_s*' ..
586586
'\d\+ ITEM 1\_s*' ..
587-
'\d\+ CHECKTYPE string stack\[-1\] arg 2\_s*' ..
587+
'\d\+ CHECKTYPE string stack\[-1\] var 2\_s*' ..
588588
'\d\+ STORE $1\_s*' ..
589589
'\d\+ SLICE 2\_s*' ..
590590
'\d\+ STORE $2\_s*' ..

src/testdir/test_vim9_script.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2302,7 +2302,7 @@ def Test_for_loop_fails()
23022302
echo k v
23032303
endfor
23042304
END
2305-
v9.CheckDefExecAndScriptFailure(lines, ['E1013: Argument 1: type mismatch, expected job but got string', 'E1012: Type mismatch; expected job but got string'], 2)
2305+
v9.CheckDefExecAndScriptFailure(lines, ['E1163: Variable 1: type mismatch, expected job but got string', 'E1012: Type mismatch; expected job but got string'], 2)
23062306

23072307
lines =<< trim END
23082308
var i = 0

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ static char *(features[]) =
746746

747747
static int included_patches[] =
748748
{ /* Add new patch number below this line */
749+
/**/
750+
4973,
749751
/**/
750752
4972,
751753
/**/

src/vim9.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ typedef struct {
296296
type_T *ct_type;
297297
int8_T ct_off; // offset in stack, -1 is bottom
298298
int8_T ct_arg_idx; // argument index or zero
299+
int8_T ct_is_var; // when TRUE checking variable instead of arg
299300
} checktype_T;
300301

301302
// arguments to ISN_STORENR

src/vim9compile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,8 @@ need_type_where(
412412
// If the actual type can be the expected type add a runtime check.
413413
if (!actual_is_const && ret == MAYBE && use_typecheck(actual, expected))
414414
{
415-
generate_TYPECHECK(cctx, expected, offset, where.wt_index);
415+
generate_TYPECHECK(cctx, expected, offset,
416+
where.wt_variable, where.wt_index);
416417
return OK;
417418
}
418419

src/vim9execute.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4652,14 +4652,17 @@ exec_instructions(ectx_T *ectx)
46524652
case ISN_CHECKTYPE:
46534653
{
46544654
checktype_T *ct = &iptr->isn_arg.type;
4655+
int save_wt_variable = ectx->ec_where.wt_variable;
46554656

46564657
tv = STACK_TV_BOT((int)ct->ct_off);
46574658
SOURCING_LNUM = iptr->isn_lnum;
46584659
if (!ectx->ec_where.wt_variable)
46594660
ectx->ec_where.wt_index = ct->ct_arg_idx;
4661+
ectx->ec_where.wt_variable = ct->ct_is_var;
46604662
if (check_typval_type(ct->ct_type, tv, ectx->ec_where)
46614663
== FAIL)
46624664
goto on_error;
4665+
ectx->ec_where.wt_variable = save_wt_variable;
46634666
if (!ectx->ec_where.wt_variable)
46644667
ectx->ec_where.wt_index = 0;
46654668

@@ -6114,18 +6117,19 @@ list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
61146117

61156118
case ISN_CHECKTYPE:
61166119
{
6117-
checktype_T *ct = &iptr->isn_arg.type;
6118-
char *tofree;
6120+
checktype_T *ct = &iptr->isn_arg.type;
6121+
char *tofree;
61196122

61206123
if (ct->ct_arg_idx == 0)
61216124
smsg("%s%4d CHECKTYPE %s stack[%d]", pfx, current,
61226125
type_name(ct->ct_type, &tofree),
61236126
(int)ct->ct_off);
61246127
else
6125-
smsg("%s%4d CHECKTYPE %s stack[%d] arg %d",
6128+
smsg("%s%4d CHECKTYPE %s stack[%d] %s %d",
61266129
pfx, current,
61276130
type_name(ct->ct_type, &tofree),
61286131
(int)ct->ct_off,
6132+
ct->ct_is_var ? "var": "arg",
61296133
(int)ct->ct_arg_idx);
61306134
vim_free(tofree);
61316135
break;

src/vim9instr.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ generate_TYPECHECK(
542542
cctx_T *cctx,
543543
type_T *expected,
544544
int offset,
545+
int is_var,
545546
int argidx)
546547
{
547548
isn_T *isn;
@@ -551,6 +552,7 @@ generate_TYPECHECK(
551552
return FAIL;
552553
isn->isn_arg.type.ct_type = alloc_type(expected);
553554
isn->isn_arg.type.ct_off = (int8_T)offset;
555+
isn->isn_arg.type.ct_is_var = is_var;
554556
isn->isn_arg.type.ct_arg_idx = (int8_T)argidx;
555557

556558
// type becomes expected
@@ -1437,7 +1439,7 @@ generate_BCALL(cctx_T *cctx, int func_idx, int argcount, int method_call)
14371439
if (maptype != NULL && maptype[0].type_decl->tt_member != NULL
14381440
&& maptype[0].type_decl->tt_member != &t_any)
14391441
// Check that map() didn't change the item types.
1440-
generate_TYPECHECK(cctx, maptype[0].type_decl, -1, 1);
1442+
generate_TYPECHECK(cctx, maptype[0].type_decl, -1, FALSE, 1);
14411443

14421444
return OK;
14431445
}

0 commit comments

Comments
 (0)