Skip to content

Commit

Permalink
patch 8.2.2771: Vim9: assignment not recognized if declaration was sk…
Browse files Browse the repository at this point in the history
…ipped

Problem:    Vim9: assignment not recognized if declaration was skipped.
Solution:   Also recognized an assignment if the variable does not exist.
            (closes #8108)
  • Loading branch information
brammool committed Apr 15, 2021
1 parent fe090eb commit aa1959b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ex_docmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions src/testdir/test_vim9_assign.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
2771,
/**/
2770,
/**/
Expand Down

0 comments on commit aa1959b

Please sign in to comment.