]> granicus.if.org Git - vim/commitdiff
patch 8.2.2705: Vim9: misleading reported line number for wrong type v8.2.2705
authorBram Moolenaar <Bram@vim.org>
Sat, 3 Apr 2021 19:01:01 +0000 (21:01 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 3 Apr 2021 19:01:01 +0000 (21:01 +0200)
Problem:    Vim9: misleading reported line number for wrong type.
Solution:   Remember and use the line number at the start. (closes #8059)

src/testdir/test_vim9_assign.vim
src/version.c
src/vim9compile.c

index 0b1d5fcb16696750159ac2a0a63f1e95ff5cb357..db8f551e8effe4ad03a5a2771ba6c0c95b2f2778 100644 (file)
@@ -315,6 +315,14 @@ def Test_assign_linebreak()
   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()
index b557d59faa910112412c021090cd0db976e94f72..db8219e5b505f58add651b00cabff7d3fb4efb31 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2705,
 /**/
     2704,
 /**/
index 3fb4a8d2051c0f1753b82c4ae307f966f5f73cfc..4d702d4f9eb003e57e84061b16cd6e63c7fbc625 100644 (file)
@@ -6166,6 +6166,7 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
     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 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
                    {
                        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,