Mercurial > vim
changeset 31867:7d505d77f6da v9.0.1266
patch 9.0.1266: error for space before ": type" is inconsistent
Commit: https://github.com/vim/vim/commit/ce93d162da8de2419c15b63286e2f72a8fe3bf2d
Author: Bram Moolenaar <Bram@vim.org>
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 30 Jan 2023 22:15:03 +0100 |
parents | b398a8a9ad05 |
children | 246a3285d573 |
files | src/eval.c src/evalvars.c src/testdir/test_vim9_assign.vim src/version.c src/vim9cmds.c src/vim9compile.c |
diffstat | 6 files changed, 29 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- 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);
--- 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; }
--- 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
--- 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,
--- 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); }
--- 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);