diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-08-07 16:30:42 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-08-07 16:30:42 +0200 |
commit | 4270d8b7626ff8a7006f6a09c89bc446a3f89d1e (patch) | |
tree | c8b632c8862523490938e53418440ac393b46788 /src/vim9compile.c | |
parent | fbeefb1b87b0d52a095c08fee47b62d290bf4c33 (diff) |
patch 8.2.3310: Vim9: unpack assignment does not mention source of type errorv8.2.3310
Problem: Vim9: unpack assignment does not mention source of type error.
Solution: Mention the argument number. (closes #8719)
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r-- | src/vim9compile.c | 37 |
1 files changed, 27 insertions, 10 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c index 5d625e0c75..125135adaa 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1039,18 +1039,16 @@ use_typecheck(type_T *actual, type_T *expected) * If "actual_is_const" is TRUE then the type won't change at runtime, do not * generate a TYPECHECK. */ - int -need_type( + static int +need_type_where( type_T *actual, type_T *expected, int offset, - int arg_idx, + where_T where, cctx_T *cctx, int silent, int actual_is_const) { - where_T where = WHERE_INIT; - if (expected == &t_bool && actual != &t_bool && (actual->tt_flags & TTFLAG_BOOL_OK)) { @@ -1060,7 +1058,6 @@ need_type( return OK; } - where.wt_index = arg_idx; if (check_type(expected, actual, FALSE, where) == OK) return OK; @@ -1069,15 +1066,32 @@ need_type( if ((!actual_is_const || actual == &t_any) && use_typecheck(actual, expected)) { - generate_TYPECHECK(cctx, expected, offset, arg_idx); + generate_TYPECHECK(cctx, expected, offset, where.wt_index); return OK; } if (!silent) - arg_type_mismatch(expected, actual, arg_idx); + type_mismatch_where(expected, actual, where); return FAIL; } + int +need_type( + type_T *actual, + type_T *expected, + int offset, + int arg_idx, + cctx_T *cctx, + int silent, + int actual_is_const) +{ + where_T where = WHERE_INIT; + + where.wt_index = arg_idx; + return need_type_where(actual, expected, offset, where, + cctx, silent, actual_is_const); +} + /* * Check that the top of the type stack has a type that can be used as a * condition. Give an error and return FAIL if not. @@ -7004,14 +7018,17 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx) else if (*op == '=') { type_T *use_type = lhs.lhs_lvar->lv_type; + where_T where = WHERE_INIT; // Without operator check type here, otherwise below. // Use the line number of the assignment. SOURCING_LNUM = start_lnum; + where.wt_index = var_count > 0 ? var_idx + 1 : 0; + where.wt_variable = var_count > 0; if (lhs.lhs_has_index) use_type = lhs.lhs_member_type; - if (need_type(rhs_type, use_type, -1, 0, cctx, - FALSE, is_const) == FAIL) + if (need_type_where(rhs_type, use_type, -1, where, + cctx, FALSE, is_const) == FAIL) goto theend; } } |