Skip to content

Commit acbae18

Browse files
committed
patch 8.2.2139: Vim9: unreachable code in assignment
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.
1 parent b5b9480 commit acbae18

3 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/testdir/test_vim9_assign.vim

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,18 @@ def Test_assign_index()
326326
END
327327
CheckDefFailure(lines, 'E1012: Type mismatch; expected number but got dict<unknown>', 3)
328328

329+
lines =<< trim END
330+
var lines: list<string>
331+
lines['a'] = 'asdf'
332+
END
333+
CheckDefFailure(lines, 'E39:', 2)
334+
335+
lines =<< trim END
336+
var lines: string
337+
lines[9] = 'asdf'
338+
END
339+
CheckDefFailure(lines, 'E1141:', 2)
340+
329341
# list of dict
330342
var ld: list<dict<number>>
331343
ld[0] = {}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,8 @@ static char *(features[]) =
750750

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2139,
753755
/**/
754756
2138,
755757
/**/

src/vim9compile.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5856,8 +5856,6 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
58565856
int r;
58575857

58585858
// Compile the "idx" in "var[idx]" or "key" in "var.key".
5859-
if (new_local)
5860-
--cctx->ctx_locals.ga_len;
58615859
p = var_start + varlen;
58625860
if (*p == '[')
58635861
{
@@ -5877,8 +5875,6 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
58775875

58785876
r = generate_PUSHS(cctx, key);
58795877
}
5880-
if (new_local)
5881-
++cctx->ctx_locals.ga_len;
58825878
if (r == FAIL)
58835879
goto theend;
58845880

0 commit comments

Comments
 (0)