patch 8.2.2705: Vim9: misleading reported line number for wrong type
Problem: Vim9: misleading reported line number for wrong type.
Solution: Remember and use the line number at the start. (closes #8059)
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index 0b1d5fc..db8f551 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -315,6 +315,14 @@
assert_equal(34, n2)
CheckDefFailure(["var x = #"], 'E1097:', 3)
+
+ var lines =<< trim END
+ var x: list<string> = ['a']
+ var y: list<number> = x
+ ->copy()
+ ->copy()
+ END
+ CheckDefFailure(lines, 'E1012:', 2)
enddef
def Test_assign_index()
diff --git a/src/version.c b/src/version.c
index b557d59..db8219e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2705,
+/**/
2704,
/**/
2703,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 3fb4a8d..4d702d4 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -6166,6 +6166,7 @@
char_u *sp;
int is_decl = is_decl_command(cmdidx);
lhs_T lhs;
+ long start_lnum = SOURCING_LNUM;
// Skip over the "var" or "[var, var]" to get to any "=".
p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE);
@@ -6393,7 +6394,9 @@
{
type_T *use_type = lhs.lhs_lvar->lv_type;
- // without operator check type here, otherwise below
+ // Without operator check type here, otherwise below.
+ // Use the line number of the assignment.
+ SOURCING_LNUM = start_lnum;
if (lhs.lhs_has_index)
use_type = lhs.lhs_member_type;
if (need_type(rhs_type, use_type, -1, 0, cctx,