Mirror of the Vim source from https://github.com/vim/vim
Revision | 11609f025219de61f30e5ca319fb9819aa033690 (tree) |
---|---|
Time | 2022-05-18 00:15:03 |
Author | Bram Moolenaar <Bram@vim....> |
Commiter | Bram Moolenaar |
patch 8.2.4973: Vim9: type error for list unpack mentions argument
Commit: https://github.com/vim/vim/commit/bd3a9d2c946bae0427d7c9b9249716064935fb4e
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue May 17 16:12:39 2022 +0100
@@ -9,9 +9,10 @@ | ||
9 | 9 | int generate_two_op(cctx_T *cctx, char_u *op); |
10 | 10 | int check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2); |
11 | 11 | int generate_COMPARE(cctx_T *cctx, exprtype_T exprtype, int ic); |
12 | +int generate_CONCAT(cctx_T *cctx, int count); | |
12 | 13 | int generate_2BOOL(cctx_T *cctx, int invert, int offset); |
13 | 14 | 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); | |
15 | 16 | int generate_SETTYPE(cctx_T *cctx, type_T *expected); |
16 | 17 | int generate_tv_PUSH(cctx_T *cctx, typval_T *tv); |
17 | 18 | int generate_PUSHNR(cctx_T *cctx, varnumber_T number); |
@@ -62,7 +63,6 @@ | ||
62 | 63 | int generate_EXECCONCAT(cctx_T *cctx, int count); |
63 | 64 | int generate_RANGE(cctx_T *cctx, char_u *range); |
64 | 65 | int generate_UNPACK(cctx_T *cctx, int var_count, int semicolon); |
65 | -int generate_CONCAT(cctx_T *cctx, int count); | |
66 | 66 | int generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod); |
67 | 67 | int generate_undo_cmdmods(cctx_T *cctx); |
68 | 68 | 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); |
@@ -581,10 +581,10 @@ | ||
581 | 581 | '\d CHECKTYPE list<any> stack\[-1\]\_s*' .. |
582 | 582 | '\d CHECKLEN >= 2\_s*' .. |
583 | 583 | '\d\+ ITEM 0\_s*' .. |
584 | - '\d\+ CHECKTYPE string stack\[-1\] arg 1\_s*' .. | |
584 | + '\d\+ CHECKTYPE string stack\[-1\] var 1\_s*' .. | |
585 | 585 | '\d\+ STORE $0\_s*' .. |
586 | 586 | '\d\+ ITEM 1\_s*' .. |
587 | - '\d\+ CHECKTYPE string stack\[-1\] arg 2\_s*' .. | |
587 | + '\d\+ CHECKTYPE string stack\[-1\] var 2\_s*' .. | |
588 | 588 | '\d\+ STORE $1\_s*' .. |
589 | 589 | '\d\+ SLICE 2\_s*' .. |
590 | 590 | '\d\+ STORE $2\_s*' .. |
@@ -2302,7 +2302,7 @@ | ||
2302 | 2302 | echo k v |
2303 | 2303 | endfor |
2304 | 2304 | 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) | |
2306 | 2306 | |
2307 | 2307 | lines =<< trim END |
2308 | 2308 | var i = 0 |
@@ -747,6 +747,8 @@ | ||
747 | 747 | static int included_patches[] = |
748 | 748 | { /* Add new patch number below this line */ |
749 | 749 | /**/ |
750 | + 4973, | |
751 | +/**/ | |
750 | 752 | 4972, |
751 | 753 | /**/ |
752 | 754 | 4971, |
@@ -296,6 +296,7 @@ | ||
296 | 296 | type_T *ct_type; |
297 | 297 | int8_T ct_off; // offset in stack, -1 is bottom |
298 | 298 | int8_T ct_arg_idx; // argument index or zero |
299 | + int8_T ct_is_var; // when TRUE checking variable instead of arg | |
299 | 300 | } checktype_T; |
300 | 301 | |
301 | 302 | // arguments to ISN_STORENR |
@@ -412,7 +412,8 @@ | ||
412 | 412 | // If the actual type can be the expected type add a runtime check. |
413 | 413 | if (!actual_is_const && ret == MAYBE && use_typecheck(actual, expected)) |
414 | 414 | { |
415 | - generate_TYPECHECK(cctx, expected, offset, where.wt_index); | |
415 | + generate_TYPECHECK(cctx, expected, offset, | |
416 | + where.wt_variable, where.wt_index); | |
416 | 417 | return OK; |
417 | 418 | } |
418 | 419 |
@@ -4652,14 +4652,17 @@ | ||
4652 | 4652 | case ISN_CHECKTYPE: |
4653 | 4653 | { |
4654 | 4654 | checktype_T *ct = &iptr->isn_arg.type; |
4655 | + int save_wt_variable = ectx->ec_where.wt_variable; | |
4655 | 4656 | |
4656 | 4657 | tv = STACK_TV_BOT((int)ct->ct_off); |
4657 | 4658 | SOURCING_LNUM = iptr->isn_lnum; |
4658 | 4659 | if (!ectx->ec_where.wt_variable) |
4659 | 4660 | ectx->ec_where.wt_index = ct->ct_arg_idx; |
4661 | + ectx->ec_where.wt_variable = ct->ct_is_var; | |
4660 | 4662 | if (check_typval_type(ct->ct_type, tv, ectx->ec_where) |
4661 | 4663 | == FAIL) |
4662 | 4664 | goto on_error; |
4665 | + ectx->ec_where.wt_variable = save_wt_variable; | |
4663 | 4666 | if (!ectx->ec_where.wt_variable) |
4664 | 4667 | ectx->ec_where.wt_index = 0; |
4665 | 4668 |
@@ -6114,18 +6117,19 @@ | ||
6114 | 6117 | |
6115 | 6118 | case ISN_CHECKTYPE: |
6116 | 6119 | { |
6117 | - checktype_T *ct = &iptr->isn_arg.type; | |
6118 | - char *tofree; | |
6120 | + checktype_T *ct = &iptr->isn_arg.type; | |
6121 | + char *tofree; | |
6119 | 6122 | |
6120 | 6123 | if (ct->ct_arg_idx == 0) |
6121 | 6124 | smsg("%s%4d CHECKTYPE %s stack[%d]", pfx, current, |
6122 | 6125 | type_name(ct->ct_type, &tofree), |
6123 | 6126 | (int)ct->ct_off); |
6124 | 6127 | else |
6125 | - smsg("%s%4d CHECKTYPE %s stack[%d] arg %d", | |
6128 | + smsg("%s%4d CHECKTYPE %s stack[%d] %s %d", | |
6126 | 6129 | pfx, current, |
6127 | 6130 | type_name(ct->ct_type, &tofree), |
6128 | 6131 | (int)ct->ct_off, |
6132 | + ct->ct_is_var ? "var": "arg", | |
6129 | 6133 | (int)ct->ct_arg_idx); |
6130 | 6134 | vim_free(tofree); |
6131 | 6135 | break; |
@@ -542,6 +542,7 @@ | ||
542 | 542 | cctx_T *cctx, |
543 | 543 | type_T *expected, |
544 | 544 | int offset, |
545 | + int is_var, | |
545 | 546 | int argidx) |
546 | 547 | { |
547 | 548 | isn_T *isn; |
@@ -551,6 +552,7 @@ | ||
551 | 552 | return FAIL; |
552 | 553 | isn->isn_arg.type.ct_type = alloc_type(expected); |
553 | 554 | isn->isn_arg.type.ct_off = (int8_T)offset; |
555 | + isn->isn_arg.type.ct_is_var = is_var; | |
554 | 556 | isn->isn_arg.type.ct_arg_idx = (int8_T)argidx; |
555 | 557 | |
556 | 558 | // type becomes expected |
@@ -1437,7 +1439,7 @@ | ||
1437 | 1439 | if (maptype != NULL && maptype[0].type_decl->tt_member != NULL |
1438 | 1440 | && maptype[0].type_decl->tt_member != &t_any) |
1439 | 1441 | // 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); | |
1441 | 1443 | |
1442 | 1444 | return OK; |
1443 | 1445 | } |