1
0
forked from aniani/vim

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 #11868)
This commit is contained in:
Bram Moolenaar 2023-01-30 21:12:34 +00:00
parent b8bebd0cd7
commit ce93d162da
6 changed files with 29 additions and 5 deletions

View 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);

View 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;
}

View 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

View File

@ -695,6 +695,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1266,
/**/
1265,
/**/

View 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);
}

View 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);