Mercurial > vim
diff src/vim9compile.c @ 19854:eddc81783052 v8.2.0483
patch 8.2.0483: Vim9: "let x = x + 1" does not give an error
Commit: https://github.com/vim/vim/commit/d25ec2cfa0c25c3b00b7f8963b8aea799df1f20a
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Mar 30 21:05:45 2020 +0200
patch 8.2.0483: Vim9: "let x = x + 1" does not give an error
Problem: Vim9: "let x = x + 1" does not give an error.
Solution: Hide the variable when compiling the expression.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 30 Mar 2020 21:15:03 +0200 |
parents | 36d629aa3d6e |
children | cf09c0962608 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -3685,6 +3685,8 @@ compile_assignment(char_u *arg, exarg_T } 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 } } - // 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))