Skip to content

Commit ccc25aa

Browse files
committed
patch 8.2.2660: Vim9: no error for declaration with trailing text
Problem: Vim9: no error for declaration with trailing text. Solution: Give an error. (closes #8014)
1 parent c61cb8b commit ccc25aa

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/evalvars.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,11 @@ ex_let(exarg_T *eap)
789789
{
790790
if (vim9script)
791791
{
792-
// Vim9 declaration ":var name: type"
793-
arg = vim9_declare_scriptvar(eap, arg);
792+
if (!ends_excmd2(eap->cmd, skipwhite(argend)))
793+
semsg(_(e_trailing_arg), argend);
794+
else
795+
// Vim9 declaration ":var name: type"
796+
arg = vim9_declare_scriptvar(eap, arg);
794797
}
795798
else
796799
{

src/testdir/test_vim9_assign.vim

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,8 @@ def Test_var_declaration()
12901290
other = 1234
12911291
g:other_var = other
12921292

1293+
var xyz: string # comment
1294+
12931295
# type is inferred
12941296
var s:dict = {['a']: 222}
12951297
def GetDictVal(key: any)
@@ -1365,7 +1367,7 @@ def Test_var_declaration_fails()
13651367
vim9script
13661368
var 9var: string
13671369
END
1368-
CheckScriptFailure(lines, 'E475:')
1370+
CheckScriptFailure(lines, 'E488:')
13691371

13701372
CheckDefFailure(['var foo.bar = 2'], 'E1087:')
13711373
CheckDefFailure(['var foo[3] = 2'], 'E1087:')
@@ -1617,6 +1619,11 @@ def Test_expr_error_no_assign()
16171619
echo x
16181620
END
16191621
CheckScriptFailureList(lines, ['E1154:', 'E121:'])
1622+
1623+
lines =<< trim END
1624+
var x: string 'string'
1625+
END
1626+
CheckDefAndScriptFailure(lines, 'E488:')
16201627
enddef
16211628

16221629

src/version.c

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

751751
static int included_patches[] =
752752
{ /* Add new patch number below this line */
753+
/**/
754+
2660,
753755
/**/
754756
2659,
755757
/**/

0 commit comments

Comments
 (0)