Mercurial > vim
changeset 23039:75241f4377a4 v8.2.2066
patch 8.2.2066: Vim9: assignment with += doesn't work
Commit: https://github.com/vim/vim/commit/ce2c5444e2556d8d156ab447d6d196f9ecd11ddc
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Nov 28 21:21:17 2020 +0100
patch 8.2.2066: Vim9: assignment with += doesn't work
Problem: Vim9: assignment with += doesn't work.
Solution: Do not see the "+" as an addition operator.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 28 Nov 2020 21:30:04 +0100 |
parents | 9af7e0556642 |
children | a549706c4024 |
files | src/eval.c src/ex_docmd.c src/testdir/test_vim9_assign.vim src/version.c |
diffstat | 4 files changed, 22 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/eval.c +++ b/src/eval.c @@ -2769,10 +2769,11 @@ eval5(char_u **arg, typval_T *rettv, eva int vim9script = in_vim9script(); // "." is only string concatenation when scriptversion is 1 + // "+=" and "-=" are assignment p = eval_next_non_blank(*arg, evalarg, &getnext); op = *p; concat = op == '.' && (*(p + 1) == '.' || current_sctx.sc_version < 2); - if (op != '+' && op != '-' && !concat) + if ((op != '+' && op != '-' && !concat) || p[1] == '=') break; evaluate = evalarg == NULL ? 0 : (evalarg->eval_flags & EVAL_EVALUATE);
--- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -3332,9 +3332,13 @@ find_ex_command( // When followed by "=" or "+=" then it is an assignment. ++emsg_silent; - if (skip_expr(&after, NULL) == OK - && (*after == '=' - || (*after != NUL && after[1] == '='))) + if (skip_expr(&after, NULL) == OK) + after = skipwhite(after); + else + after = (char_u *)""; + if (*after == '=' || (*after != NUL && after[1] == '=') + || (after[0] == '.' && after[1] == '.' + && after[2] == '=')) eap->cmdidx = CMD_var; else eap->cmdidx = CMD_eval;
--- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -866,18 +866,17 @@ def Test_assign_dict_unknown_type() END CheckScriptSuccess(lines) - # doesn't work yet - #lines =<< trim END - # vim9script - # var mylist = [[]] - # mylist[0] += [#{one: 'one'}] - # def Func() - # var dd = mylist[0][0] - # assert_equal('one', dd.one) - # enddef - # Func() - #END - #CheckScriptSuccess(lines) + lines =<< trim END + vim9script + var mylist = [[]] + mylist[0] += [#{one: 'one'}] + def Func() + var dd = mylist[0][0] + assert_equal('one', dd.one) + enddef + Func() + END + CheckScriptSuccess(lines) enddef def Test_assign_lambda()