]> granicus.if.org Git - vim/commitdiff
patch 8.2.0624: Vim9: no check for space before #comment v8.2.0624
authorBram Moolenaar <Bram@vim.org>
Thu, 23 Apr 2020 15:07:30 +0000 (17:07 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 23 Apr 2020 15:07:30 +0000 (17:07 +0200)
Problem:    Vim9: no check for space before #comment.
Solution:   Add space checks.  Fix :throw with double quoted string.

src/testdir/test_vim9_script.vim
src/usercmd.c
src/userfunc.c
src/version.c
src/vim9compile.c

index 219a86f2701ca0f6ae702313d18d6a8d4e0c77e9..5eda50b733f186f2b2ab5709d01bc982ef9df6ad 100644 (file)
@@ -361,7 +361,7 @@ def Test_try_catch()
 enddef
 
 def ThrowFromDef()
-  throw 'getout'
+  throw "getout" # comment
 enddef
 
 func CatchInFunc()
@@ -430,7 +430,7 @@ def Test_try_catch_fails()
   call CheckDefFailure(['if 2', 'endtry'], 'E171:')
   call CheckDefFailure(['try', 'echo 1', 'endtry'], 'E1032:')
 
-  call CheckDefFailure(['throw'], 'E471:')
+  call CheckDefFailure(['throw'], 'E1015:')
   call CheckDefFailure(['throw xxx'], 'E1001:')
 enddef
 
@@ -937,12 +937,18 @@ def Test_execute_cmd()
   setline(1, 'default')
   execute 'call setline(1, "execute-string")'
   assert_equal('execute-string', getline(1))
+
+  execute "call setline(1, 'execute-string')"
+  assert_equal('execute-string', getline(1))
+
   let cmd1 = 'call setline(1,'
   let cmd2 = '"execute-var")'
-  execute cmd1 cmd2
+  execute cmd1 cmd2 # comment
   assert_equal('execute-var', getline(1))
+
   execute cmd1 cmd2 '|call setline(1, "execute-var-string")'
   assert_equal('execute-var-string', getline(1))
+
   let cmd_first = 'call '
   let cmd_last = 'setline(1, "execute-var-var")'
   execute cmd_first .. cmd_last
@@ -950,17 +956,24 @@ def Test_execute_cmd()
   bwipe!
 
   call CheckDefFailure(['execute xxx'], 'E1001:')
+  call CheckDefFailure(['execute "cmd"# comment'], 'E488:')
 enddef
 
 def Test_echo_cmd()
-  echo 'some'
+  echo 'some' # comment
   echon 'thing'
   assert_match('^something$', Screenline(&lines))
 
+  echo "some" # comment
+  echon "thing"
+  assert_match('^something$', Screenline(&lines))
+
   let str1 = 'some'
   let str2 = 'more'
   echo str1 str2
   assert_match('^some more$', Screenline(&lines))
+
+  call CheckDefFailure(['echo "xxx"# comment'], 'E488:')
 enddef
 
 def Test_for_outside_of_function()
@@ -1162,6 +1175,18 @@ def Test_vim9_comment()
       'try# comment',
       'echo "yes"',
       ], 'E488:')
+  CheckDefFailure([
+      'try',
+      '  throw#comment',
+      'catch',
+      'endtry',
+      ], 'E1015:')
+  CheckDefFailure([
+      'try',
+      '  throw "yes"#comment',
+      'catch',
+      'endtry',
+      ], 'E488:')
   CheckDefFailure([
       'try',
       '  echo "yes"',
@@ -1380,6 +1405,65 @@ def Test_vim9_comment()
       'vim9script',
       'syntax cluster Some contains=Word# comment',
       ], 'E475:')
+
+  CheckScriptSuccess([
+      'vim9script',
+      'command Echo echo # comment',
+      'command Echo # comment',
+      ])
+  CheckScriptFailure([
+      'vim9script',
+      'command Echo echo# comment',
+      'Echo',
+      ], 'E121:')
+  CheckScriptFailure([
+      'vim9script',
+      'command Echo# comment',
+      ], 'E182:')
+  CheckScriptFailure([
+      'vim9script',
+      'command Echo echo',
+      'command Echo# comment',
+      ], 'E182:')
+
+  CheckScriptSuccess([
+      'vim9script',
+      'function # comment',
+      ])
+  CheckScriptFailure([
+      'vim9script',
+      'function# comment',
+      ], 'E129:')
+  CheckScriptSuccess([
+      'vim9script',
+      'function CheckScriptSuccess # comment',
+      ])
+  CheckScriptFailure([
+      'vim9script',
+      'function CheckScriptSuccess# comment',
+      ], 'E488:')
+
+  CheckScriptSuccess([
+      'vim9script',
+      'func DeleteMe()',
+      'endfunc',
+      'delfunction DeleteMe # comment',
+      ])
+  CheckScriptFailure([
+      'vim9script',
+      'func DeleteMe()',
+      'endfunc',
+      'delfunction DeleteMe# comment',
+      ], 'E488:')
+
+  CheckScriptSuccess([
+      'vim9script',
+      'call execute("ls") # comment',
+      ])
+  CheckScriptFailure([
+      'vim9script',
+      'call execute("ls")# comment',
+      ], 'E488:')
 enddef
 
 def Test_vim9_comment_gui()
index fc14430b64ca00d8b1a74c8d42b96a5d4ec9277f..cdc46a10b9550933582da46048335243e63cf914 100644 (file)
@@ -1007,7 +1007,7 @@ ex_command(exarg_T *eap)
     if (ASCII_ISALPHA(*p))
        while (ASCII_ISALNUM(*p))
            ++p;
-    if (!ends_excmd(*p) && !VIM_ISWHITE(*p))
+    if (!ends_excmd2(eap->arg, p) && !VIM_ISWHITE(*p))
     {
        emsg(_("E182: Invalid command name"));
        return;
@@ -1018,7 +1018,7 @@ ex_command(exarg_T *eap)
     // If there is nothing after the name, and no attributes were specified,
     // we are listing commands
     p = skipwhite(end);
-    if (!has_attr && ends_excmd(*p))
+    if (!has_attr && ends_excmd2(eap->arg, p))
     {
        uc_list(name, end - name);
     }
index dfda733a1c4bb6971a0a785e4414554f84548987..698c1b1e3dd2d66cb84d1655aabd9b639e53cfb3 100644 (file)
@@ -2373,7 +2373,7 @@ ex_function(exarg_T *eap)
     /*
      * ":function" without argument: list functions.
      */
-    if (ends_excmd(*eap->arg))
+    if (ends_excmd2(eap->cmd, eap->arg))
     {
        if (!eap->skip)
        {
@@ -3711,7 +3711,7 @@ ex_call(exarg_T *eap)
     if (!failed || eap->cstack->cs_trylevel > 0)
     {
        // Check for trailing illegal characters and a following command.
-       if (!ends_excmd(*arg))
+       if (!ends_excmd2(eap->arg, arg))
        {
            if (!failed)
            {
index b2268736f11d2c78eb7d66d2756f7fe95572cfeb..86cfce095725c487e8f6e12bfcdb49e14470dfd0 100644 (file)
@@ -746,6 +746,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    624,
 /**/
     623,
 /**/
index daa1cbea41170017687bcdf336fba5d2c6bb0e0c..393d2b824c942b288f1d751bc1088452d0d778cb 100644 (file)
@@ -5752,11 +5752,6 @@ compile_throw(char_u *arg, cctx_T *cctx UNUSED)
 {
     char_u *p = skipwhite(arg);
 
-    if (ends_excmd(*p))
-    {
-       emsg(_(e_argreq));
-       return NULL;
-    }
     if (compile_expr1(&p, cctx) == FAIL)
        return NULL;
     if (may_generate_2STRING(-1, cctx) == FAIL)