# HG changeset patch # User Bram Moolenaar # Date 1618517703 -7200 # Node ID 7c4f50c02e18c8f26fc8b820200d434f5814f6de # Parent 550096cdfa95b02fd82889e195c7fd658efee37c patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped Commit: https://github.com/vim/vim/commit/aa1959bd5e82350bb4a82d9a5188c29d70706ec4 Author: Bram Moolenaar Date: Thu Apr 15 22:13:39 2021 +0200 patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped Problem: Vim9: assignment not recognized if declaration was skipped. Solution: Also recognized an assignment if the variable does not exist. (closes #8108) diff --git a/src/ex_docmd.c b/src/ex_docmd.c --- a/src/ex_docmd.c +++ b/src/ex_docmd.c @@ -3483,7 +3483,8 @@ find_ex_command( // Recognize an assignment if we recognize the variable name: // "g:var = expr" - // "var = expr" where "var" is a variable name. + // "var = expr" where "var" is a variable name or we are skipping + // (variable declaration might have been skipped). if (*eap->cmd == '@') p = eap->cmd + 2; oplen = assignment_len(skipwhite(p), &heredoc); @@ -3493,6 +3494,7 @@ find_ex_command( || *eap->cmd == '&' || *eap->cmd == '$' || *eap->cmd == '@' + || eap->skip || lookup(eap->cmd, p - eap->cmd, TRUE, cctx) == OK) { eap->cmdidx = CMD_var; diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -249,6 +249,18 @@ def Test_assignment() END enddef +def Test_skipped_assignment() + var lines =<< trim END + for x in [] + var i: number = 1 + while false + i += 1 + endwhile + endfor + END + CheckDefAndScriptSuccess(lines) +enddef + def Test_assign_unpack() var lines =<< trim END var v1: number diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 2771, +/**/ 2770, /**/ 2769,