]> granicus.if.org Git - vim/commitdiff
patch 8.2.2771: Vim9: assignment not recognized if declaration was skipped v8.2.2771
authorBram Moolenaar <Bram@vim.org>
Thu, 15 Apr 2021 20:13:39 +0000 (22:13 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 15 Apr 2021 20:13:39 +0000 (22:13 +0200)
Problem:    Vim9: assignment not recognized if declaration was skipped.
Solution:   Also recognized an assignment if the variable does not exist.
            (closes #8108)

src/ex_docmd.c
src/testdir/test_vim9_assign.vim
src/version.c

index 83f49d0d378b375edabbf0e810495286b5e8a48c..db7bb931f8fc412b43c0cc481c4e7bba9e3cdc36 100644 (file)
@@ -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;
index 958b7b980944fa121d00d788cd6ebf02f6bb3c99..ad942a8f17780ed0f772e86eef34fd66278ac139 100644 (file)
@@ -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
index 8cbe3d36d7b2b90c9f7e87392846550b480fcd56..44cf5ffd0c68cc5f53b06e09464c56b7caafc1ef 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2771,
 /**/
     2770,
 /**/