]> granicus.if.org Git - vim/commitdiff
patch 8.2.2660: Vim9: no error for declaration with trailing text v8.2.2660
authorBram Moolenaar <Bram@vim.org>
Fri, 26 Mar 2021 20:27:52 +0000 (21:27 +0100)
committerBram Moolenaar <Bram@vim.org>
Fri, 26 Mar 2021 20:27:52 +0000 (21:27 +0100)
Problem:    Vim9: no error for declaration with trailing text.
Solution:   Give an error. (closes #8014)

src/evalvars.c
src/testdir/test_vim9_assign.vim
src/version.c

index 79c7a9c8c4af1992de7ccb840efbf875c6d1837b..cd50ba7fdd384b62d49a01e008e97d79938d752c 100644 (file)
@@ -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
            {
index f71226e1bd94015dda45cd9747bbf7ab8b1876bc..b9851a77f56af928af2e0bbf5c969f557dde3676 100644 (file)
@@ -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
 
 
index 373ec74b1e0cdac4bb9114f2abb3405e841d1221..f172437afe82a474fd8baf87e79229e360070af4 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2660,
 /**/
     2659,
 /**/