Skip to content

Commit ce93d16

Browse files
committed
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)
1 parent b8bebd0 commit ce93d16

6 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/eval.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ get_lval(
10931093
--p;
10941094
lp->ll_name_end = p;
10951095
}
1096-
if (*p == ':')
1096+
if (*skipwhite(p) == ':')
10971097
{
10981098
char_u *tp = skipwhite(p + 1);
10991099

@@ -1102,6 +1102,11 @@ get_lval(
11021102
semsg(_(e_cannot_use_type_with_this_variable_str), name);
11031103
return NULL;
11041104
}
1105+
if (VIM_ISWHITE(*p))
1106+
{
1107+
semsg(_(e_no_white_space_allowed_before_colon_str), p);
1108+
return NULL;
1109+
}
11051110
if (tp == p + 1 && !quiet)
11061111
{
11071112
semsg(_(e_white_space_required_after_str_str), ":", p);

src/evalvars.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,8 +1363,8 @@ skip_var_one(char_u *arg, int include_type)
13631363

13641364
if (include_type && vim9)
13651365
{
1366-
if (*end == ':')
1367-
end = skip_type(skipwhite(end + 1), FALSE);
1366+
if (*skipwhite(end) == ':')
1367+
end = skip_type(skipwhite(skipwhite(end) + 1), FALSE);
13681368
}
13691369
return end;
13701370
}

src/testdir/test_vim9_assign.vim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,13 @@ def Test_null_values()
360360
v9.CheckDefAndScriptSuccess(lines)
361361
enddef
362362

363+
def Test_type_with_extra_white()
364+
var lines =<< trim END
365+
const x : number = 3
366+
END
367+
v9.CheckDefExecAndScriptFailure(lines, 'E1059')
368+
enddef
369+
363370
def Test_keep_type_after_assigning_null()
364371
var lines =<< trim END
365372
var b: blob

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,8 @@ static char *(features[]) =
695695

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
1266,
698700
/**/
699701
1265,
700702
/**/

src/vim9cmds.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,13 @@ compile_for(char_u *arg_start, cctx_T *cctx)
10011001
name = vim_strnsave(arg, varlen);
10021002
if (name == NULL)
10031003
goto failed;
1004-
if (*p == ':')
1004+
if (*skipwhite(p) == ':')
10051005
{
1006+
if (VIM_ISWHITE(*p))
1007+
{
1008+
semsg(_(e_no_white_space_allowed_before_colon_str), p);
1009+
goto failed;
1010+
}
10061011
p = skipwhite(p + 1);
10071012
lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE);
10081013
}

src/vim9compile.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,11 +1741,16 @@ compile_lhs(
17411741

17421742
if (lhs->lhs_dest != dest_option && lhs->lhs_dest != dest_func_option)
17431743
{
1744-
if (is_decl && *var_end == ':')
1744+
if (is_decl && *skipwhite(var_end) == ':')
17451745
{
17461746
char_u *p;
17471747

17481748
// parse optional type: "let var: type = expr"
1749+
if (VIM_ISWHITE(*var_end))
1750+
{
1751+
semsg(_(e_no_white_space_allowed_before_colon_str), var_end);
1752+
return FAIL;
1753+
}
17491754
if (!VIM_ISWHITE(var_end[1]))
17501755
{
17511756
semsg(_(e_white_space_required_after_str_str), ":", var_end);

0 commit comments

Comments
 (0)