# HG changeset patch # User Bram Moolenaar # Date 1675113303 -3600 # Node ID 7d505d77f6dab20f7d0be5da08b612466f586660 # Parent b398a8a9ad059f9b2406683e146fd98d7b71affd patch 9.0.1266: error for space before ": type" is inconsistent Commit: https://github.com/vim/vim/commit/ce93d162da8de2419c15b63286e2f72a8fe3bf2d Author: Bram Moolenaar Date: Mon Jan 30 21:12:34 2023 +0000 patch 9.0.1266: error for space before ": type" is inconsistent Problem: Error for space before ": type" is inconsistent. Solution: Give E1059 in more places. (closes https://github.com/vim/vim/issues/11868) diff --git a/src/eval.c b/src/eval.c --- a/src/eval.c +++ b/src/eval.c @@ -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); diff --git a/src/evalvars.c b/src/evalvars.c --- a/src/evalvars.c +++ b/src/evalvars.c @@ -1363,8 +1363,8 @@ skip_var_one(char_u *arg, int include_ty 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; } diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -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 diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -696,6 +696,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1266, +/**/ 1265, /**/ 1264, diff --git a/src/vim9cmds.c b/src/vim9cmds.c --- a/src/vim9cmds.c +++ b/src/vim9cmds.c @@ -1001,8 +1001,13 @@ compile_for(char_u *arg_start, cctx_T *c 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); } diff --git a/src/vim9compile.c b/src/vim9compile.c --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -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);