summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-03-30 21:05:45 +0200
committerBram Moolenaar <Bram@vim.org>2020-03-30 21:05:45 +0200
commitd25ec2cfa0c25c3b00b7f8963b8aea799df1f20a (patch)
treee3cfefe979dd73574dec6f8edc5388b6afba0a5e
parentca68ae13114619df3e4c195b41ad0575516f5ff6 (diff)
downloadvim-git-d25ec2cfa0c25c3b00b7f8963b8aea799df1f20a.tar.gz
patch 8.2.0483: Vim9: "let x = x + 1" does not give an errorv8.2.0483
Problem: Vim9: "let x = x + 1" does not give an error. Solution: Hide the variable when compiling the expression.
-rw-r--r--src/testdir/test_vim9_expr.vim2
-rw-r--r--src/version.c2
-rw-r--r--src/vim9compile.c12
3 files changed, 14 insertions, 2 deletions
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index f61ff536a..770890ec3 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -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
diff --git a/src/version.c b/src/version.c
index 2e8420c5e..79d50ee42 100644
--- a/src/version.c
+++ b/src/version.c
@@ -739,6 +739,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 483,
+/**/
482,
/**/
481,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 9d66e5ed1..1e8cd03d0 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -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 != '=')
{
@@ -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))