]> granicus.if.org Git - vim/commitdiff
patch 9.0.1266: error for space before ": type" is inconsistent v9.0.1266
authorBram Moolenaar <Bram@vim.org>
Mon, 30 Jan 2023 21:12:34 +0000 (21:12 +0000)
committerBram Moolenaar <Bram@vim.org>
Mon, 30 Jan 2023 21:12:34 +0000 (21:12 +0000)
Problem:    Error for space before ": type" is inconsistent.
Solution:   Give E1059 in more places. (closes #11868)

src/eval.c
src/evalvars.c
src/testdir/test_vim9_assign.vim
src/version.c
src/vim9cmds.c
src/vim9compile.c

index 699f43baceda2ac421d6c2bb280938e58e53adcb..a0bbabfe3c28d07fc5454a56d4cd27c6292c73eb 100644 (file)
@@ -1093,7 +1093,7 @@ get_lval(
                --p;
                lp->ll_name_end = p;
            }
-           if (*p == ':')
+           if (*skipwhite(p) == ':')
            {
                char_u      *tp = skipwhite(p + 1);
 
@@ -1102,6 +1102,11 @@ get_lval(
                    semsg(_(e_cannot_use_type_with_this_variable_str), name);
                    return NULL;
                }
+               if (VIM_ISWHITE(*p))
+               {
+                   semsg(_(e_no_white_space_allowed_before_colon_str), p);
+                   return NULL;
+               }
                if (tp == p + 1 && !quiet)
                {
                    semsg(_(e_white_space_required_after_str_str), ":", p);
index 68df1cb52e285fb21f5f9131ba70dd56a8ca0a9b..066543669b1b8d3d5aa65521fc84223b87b17da8 100644 (file)
@@ -1363,8 +1363,8 @@ skip_var_one(char_u *arg, int include_type)
 
     if (include_type && vim9)
     {
-       if (*end == ':')
-           end = skip_type(skipwhite(end + 1), FALSE);
+       if (*skipwhite(end) == ':')
+           end = skip_type(skipwhite(skipwhite(end) + 1), FALSE);
     }
     return end;
 }
index f016ae3f799fe8657ce79d198520b8e16b9675c3..4f4e58e069238c2399dd5b3807791b23ef5fe9ef 100644 (file)
@@ -360,6 +360,13 @@ def Test_null_values()
   v9.CheckDefAndScriptSuccess(lines)
 enddef
 
+def Test_type_with_extra_white()
+  var lines =<< trim END
+      const x : number = 3
+  END
+  v9.CheckDefExecAndScriptFailure(lines, 'E1059')
+enddef
+
 def Test_keep_type_after_assigning_null()
   var lines =<< trim END
       var b: blob
index 24a27707aae1543879813d9108cff4464dd833f7..dcf223ea8c3a96c527a02ee4cfd9dbe529861e2e 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1266,
 /**/
     1265,
 /**/
index 69c04aec9b22e657dc43febe271f0b0db2b82d61..fb09780cb36b385cd8b426e728879eb84c02ee1a 100644 (file)
@@ -1001,8 +1001,13 @@ compile_for(char_u *arg_start, cctx_T *cctx)
            name = vim_strnsave(arg, varlen);
            if (name == NULL)
                goto failed;
-           if (*p == ':')
+           if (*skipwhite(p) == ':')
            {
+               if (VIM_ISWHITE(*p))
+               {
+                   semsg(_(e_no_white_space_allowed_before_colon_str), p);
+                   goto failed;
+               }
                p = skipwhite(p + 1);
                lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE);
            }
index 27b71f78fd43502d9c2f76d27ad175bb09b3756c..a3bb411e87f606afeac849a81cdcad82e0ed6856 100644 (file)
@@ -1741,11 +1741,16 @@ compile_lhs(
 
     if (lhs->lhs_dest != dest_option && lhs->lhs_dest != dest_func_option)
     {
-       if (is_decl && *var_end == ':')
+       if (is_decl && *skipwhite(var_end) == ':')
        {
            char_u *p;
 
            // parse optional type: "let var: type = expr"
+           if (VIM_ISWHITE(*var_end))
+           {
+               semsg(_(e_no_white_space_allowed_before_colon_str), var_end);
+               return FAIL;
+           }
            if (!VIM_ISWHITE(var_end[1]))
            {
                semsg(_(e_white_space_required_after_str_str), ":", var_end);