Skip to content

Commit

Permalink
patch 8.2.0483: Vim9: "let x = x + 1" does not give an error
Browse files Browse the repository at this point in the history
Problem:    Vim9: "let x = x + 1" does not give an error.
Solution:   Hide the variable when compiling the expression.
  • Loading branch information
brammool committed Mar 30, 2020
1 parent ca68ae1 commit d25ec2c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/testdir/test_vim9_expr.vim
Expand Up @@ -738,6 +738,8 @@ def Test_expr7_dict()
call CheckDefFailure("let x = {'a': xxx}", 'E1001:')
call CheckDefFailure("let x = {xxx: 8}", 'E1001:')
call CheckDefFailure("let x = #{a: 1, a: 2}", 'E721:')
call CheckDefFailure("let x += 1", 'E1020:')
call CheckDefFailure("let x = x + 1", 'E1001:')
call CheckDefExecFailure("let x = g:anint.member", 'E715:')
call CheckDefExecFailure("let x = g:dict_empty.member", 'E716:')
enddef
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Expand Up @@ -738,6 +738,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
483,
/**/
482,
/**/
Expand Down
12 changes: 10 additions & 2 deletions src/vim9compile.c
Expand Up @@ -3685,6 +3685,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
}
else if (oplen > 0)
{
int r;

// for "+=", "*=", "..=" etc. first load the current value
if (*op != '=')
{
Expand Down Expand Up @@ -3717,10 +3719,16 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
}
}

// compile the expression
// Compile the expression. Temporarily hide the new local variable
// here, it is not available to this expression.
if (idx >= 0)
--cctx->ctx_locals.ga_len;
instr_count = instr->ga_len;
p = skipwhite(p + oplen);
if (compile_expr1(&p, cctx) == FAIL)
r = compile_expr1(&p, cctx);
if (idx >= 0)
++cctx->ctx_locals.ga_len;
if (r == FAIL)
goto theend;

if (idx >= 0 && (is_decl || !has_type))
Expand Down

0 comments on commit d25ec2c

Please sign in to comment.