0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

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)
This commit is contained in:
Bram Moolenaar
2021-04-15 22:13:39 +02:00
parent fe090eb58f
commit aa1959bd5e
3 changed files with 17 additions and 1 deletions

View File

@@ -3483,7 +3483,8 @@ find_ex_command(
// Recognize an assignment if we recognize the variable name: // Recognize an assignment if we recognize the variable name:
// "g:var = expr" // "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 == '@') if (*eap->cmd == '@')
p = eap->cmd + 2; p = eap->cmd + 2;
oplen = assignment_len(skipwhite(p), &heredoc); oplen = assignment_len(skipwhite(p), &heredoc);
@@ -3493,6 +3494,7 @@ find_ex_command(
|| *eap->cmd == '&' || *eap->cmd == '&'
|| *eap->cmd == '$' || *eap->cmd == '$'
|| *eap->cmd == '@' || *eap->cmd == '@'
|| eap->skip
|| lookup(eap->cmd, p - eap->cmd, TRUE, cctx) == OK) || lookup(eap->cmd, p - eap->cmd, TRUE, cctx) == OK)
{ {
eap->cmdidx = CMD_var; eap->cmdidx = CMD_var;

View File

@@ -249,6 +249,18 @@ def Test_assignment()
END END
enddef 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() def Test_assign_unpack()
var lines =<< trim END var lines =<< trim END
var v1: number var v1: number

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
2771,
/**/ /**/
2770, 2770,
/**/ /**/