]> granicus.if.org Git - vim/commitdiff
patch 8.2.3111: Vim9: confusing error with extra whitespace before colon v8.2.3111
authorBram Moolenaar <Bram@vim.org>
Mon, 5 Jul 2021 19:41:48 +0000 (21:41 +0200)
committerBram Moolenaar <Bram@vim.org>
Mon, 5 Jul 2021 19:41:48 +0000 (21:41 +0200)
Problem:    Vim9: confusing error with extra whitespace before colon.
Solution:   Check for colon after white space. (closes #8513)

src/eval.c
src/testdir/test_vim9_script.vim
src/version.c
src/vim9compile.c

index f57001647c5271dbc29bc378e37cbceb569b6ede..1a84d2c1f5fc09ed932c04f655d70c5f2d4ef06c 100644 (file)
@@ -1660,6 +1660,7 @@ eval_for_line(
     evalarg_T  *evalarg)
 {
     forinfo_T  *fi;
+    char_u     *var_list_end;
     char_u     *expr;
     typval_T   tv;
     list_T     *l;
@@ -1671,15 +1672,19 @@ eval_for_line(
     if (fi == NULL)
        return NULL;
 
-    expr = skip_var_list(arg, TRUE, &fi->fi_varcount, &fi->fi_semicolon, FALSE);
-    if (expr == NULL)
+    var_list_end = skip_var_list(arg, TRUE, &fi->fi_varcount,
+                                                    &fi->fi_semicolon, FALSE);
+    if (var_list_end == NULL)
        return fi;
 
-    expr = skipwhite_and_linebreak(expr, evalarg);
+    expr = skipwhite_and_linebreak(var_list_end, evalarg);
     if (expr[0] != 'i' || expr[1] != 'n'
                                  || !(expr[2] == NUL || VIM_ISWHITE(expr[2])))
     {
-       emsg(_(e_missing_in));
+       if (in_vim9script() && *expr == ':' && expr != var_list_end)
+           semsg(_(e_no_white_space_allowed_before_colon_str), expr);
+       else
+           emsg(_(e_missing_in));
        return fi;
     }
 
index 9cf098917c0151cf7581e7a7c58d4d4d884113c7..9d54899a66f63cd41bf450e2d7d2d70b90f4b10b 100644 (file)
@@ -2566,6 +2566,13 @@ def Test_for_loop_fails()
       endfor
   END
   CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected number but got string', 1)
+
+  lines =<< trim END
+      for n : number in [1, 2]
+        echo n
+      endfor
+  END
+  CheckDefAndScriptFailure(lines, 'E1059:', 1)
 enddef
 
 def Test_for_loop_script_var()
index b448822d5ae90f8d192f023bf2c133be040826fd..0653c2797c5d7b5cf3c8a445ee0992478fe8f009 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3111,
 /**/
     3110,
 /**/
index 9569f2f4d3126b9af80757146f11905250393f78..d63073676432efa3622f1ffd698961a5006a0609 100644 (file)
@@ -7775,7 +7775,10 @@ compile_for(char_u *arg_start, cctx_T *cctx)
        return NULL;
     if (STRNCMP(p, "in", 2) != 0 || !IS_WHITE_OR_NUL(p[2]))
     {
-       emsg(_(e_missing_in));
+       if (*p == ':' && wp != p)
+           semsg(_(e_no_white_space_allowed_before_colon_str), p);
+       else
+           emsg(_(e_missing_in));
        return NULL;
     }
     wp = p + 2;