changeset 24238:e5cd25f7ffcd v8.2.2660

patch 8.2.2660: Vim9: no error for declaration with trailing text Commit: https://github.com/vim/vim/commit/ccc25aa285498d572a735bba5afd22aec9f605f4 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Mar 26 21:27:52 2021 +0100 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 https://github.com/vim/vim/issues/8014)
author Bram Moolenaar <Bram@vim.org>
date Fri, 26 Mar 2021 21:30:03 +0100
parents 3e21ce770d08
children 4abfff4a120d
files src/evalvars.c src/testdir/test_vim9_assign.vim src/version.c
diffstat 3 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -789,8 +789,11 @@ ex_let(exarg_T *eap)
 	{
 	    if (vim9script)
 	    {
-		// Vim9 declaration ":var name: type"
-		arg = vim9_declare_scriptvar(eap, arg);
+		if (!ends_excmd2(eap->cmd, skipwhite(argend)))
+		    semsg(_(e_trailing_arg), argend);
+		else
+		    // Vim9 declaration ":var name: type"
+		    arg = vim9_declare_scriptvar(eap, arg);
 	    }
 	    else
 	    {
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -1290,6 +1290,8 @@ def Test_var_declaration()
     other = 1234
     g:other_var = other
 
+    var xyz: string  # comment
+
     # type is inferred
     var s:dict = {['a']: 222}
     def GetDictVal(key: any)
@@ -1365,7 +1367,7 @@ def Test_var_declaration_fails()
     vim9script
     var 9var: string
   END
-  CheckScriptFailure(lines, 'E475:')
+  CheckScriptFailure(lines, 'E488:')
 
   CheckDefFailure(['var foo.bar = 2'], 'E1087:')
   CheckDefFailure(['var foo[3] = 2'], 'E1087:')
@@ -1617,6 +1619,11 @@ def Test_expr_error_no_assign()
       echo x
   END
   CheckScriptFailureList(lines, ['E1154:', 'E121:'])
+
+  lines =<< trim END
+      var x: string  'string'
+  END
+  CheckDefAndScriptFailure(lines, 'E488:')
 enddef
 
 
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2660,
+/**/
     2659,
 /**/
     2658,