]> granicus.if.org Git - vim/commitdiff
patch 8.2.2139: Vim9: unreachable code in assignment v8.2.2139
authorBram Moolenaar <Bram@vim.org>
Sun, 13 Dec 2020 17:44:43 +0000 (18:44 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 13 Dec 2020 17:44:43 +0000 (18:44 +0100)
Problem:    Vim9: unreachable code in assignment.
Solution:   Don't check "new_local" when "has_index" is set.  Add test for
            wrong type of list index.

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

index 1075e171225673ec36553945d8de0372f78e86f7..60c8fe958959f296ea7587f690ead214a0978b28 100644 (file)
@@ -326,6 +326,18 @@ def Test_assign_index()
   END
   CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got dict<unknown>', 3)
 
+  lines =<< trim END
+    var lines: list<string>
+    lines['a'] = 'asdf'
+  END
+  CheckDefFailure(lines, 'E39:', 2)
+
+  lines =<< trim END
+    var lines: string
+    lines[9] = 'asdf'
+  END
+  CheckDefFailure(lines, 'E1141:', 2)
+
   # list of dict
   var ld: list<dict<number>>
   ld[0] = {}
index 2d39c1be5a624fd49b748e353d6468a472b2a20c..f6c51e1f0afd08f5f954d8907a4ac055cf322c1e 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2139,
 /**/
     2138,
 /**/
index 6cbf7849ecd8a9e5ed483265d8254f9d0ca7b9b8..3fae25e1152c6f58227a467e5d894f0998ddf374 100644 (file)
@@ -5856,8 +5856,6 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
            int r;
 
            // Compile the "idx" in "var[idx]" or "key" in "var.key".
-           if (new_local)
-               --cctx->ctx_locals.ga_len;
            p = var_start + varlen;
            if (*p == '[')
            {
@@ -5877,8 +5875,6 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
 
                r = generate_PUSHS(cctx, key);
            }
-           if (new_local)
-               ++cctx->ctx_locals.ga_len;
            if (r == FAIL)
                goto theend;