]> granicus.if.org Git - vim/commitdiff
patch 8.2.1268: Vim9: no error for using double quote comment v8.2.1268
authorBram Moolenaar <Bram@vim.org>
Wed, 22 Jul 2020 16:17:08 +0000 (18:17 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 22 Jul 2020 16:17:08 +0000 (18:17 +0200)
Problem:    Vim9: no error for using double quote comment after :func or :def.
Solution:   Only accept double quote when not in Vim9 script and not after
            :def. (closes #6483)

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

index 59727a2fd4af888ede30adb1b1c8d01a8c8d0dec..5fec8a2746f927f34201e6602a78b76b77da02a4 100644 (file)
@@ -2198,6 +2198,35 @@ def Test_vim9_comment()
       'vim9script',
       'call execute("ls")# comment',
       ], 'E488:')
+
+  CheckScriptFailure([
+      'def Test() " comment',
+      'enddef',
+      ], 'E488:')
+  CheckScriptFailure([
+      'vim9script',
+      'def Test() " comment',
+      'enddef',
+      ], 'E488:')
+
+  CheckScriptSuccess([
+      'func Test() " comment',
+      'endfunc',
+      ])
+  CheckScriptFailure([
+      'vim9script',
+      'func Test() " comment',
+      'endfunc',
+      ], 'E488:')
+
+  CheckScriptSuccess([
+      'def Test() # comment',
+      'enddef',
+      ])
+  CheckScriptFailure([
+      'func Test() # comment',
+      'endfunc',
+      ], 'E488:')
 enddef
 
 def Test_vim9_comment_gui()
index eda1f242f536559a8876a8d1f13c7787aed90c82..3967d2743dfbb768365bac6a66bc576b482358f3 100644 (file)
@@ -2555,8 +2555,9 @@ def_function(exarg_T *eap, char_u *name_arg)
     int                is_heredoc = FALSE;
     char_u     *skip_until = NULL;
     char_u     *heredoc_trimmed = NULL;
+    int                vim9script = in_vim9script();
 
-    if (in_vim9script() && eap->forceit)
+    if (vim9script && eap->forceit)
     {
        emsg(_(e_nobang));
        return NULL;
@@ -2786,6 +2787,7 @@ def_function(exarg_T *eap, char_u *name_arg)
                ret_type = NULL;
            }
        }
+       p = skipwhite(p);
     }
     else
        // find extra arguments "range", "dict", "abort" and "closure"
@@ -2826,8 +2828,11 @@ def_function(exarg_T *eap, char_u *name_arg)
     // Makes 'exe "func Test()\n...\nendfunc"' work.
     if (*p == '\n')
        line_arg = p + 1;
-    else if (*p != NUL && *p != '"' && !(eap->cmdidx == CMD_def && *p == '#')
-                                                   && !eap->skip && !did_emsg)
+    else if (*p != NUL
+           && !(*p == '"' && !(vim9script || eap->cmdidx == CMD_def))
+           && !(*p == '#' && (vim9script || eap->cmdidx == CMD_def))
+           && !eap->skip
+           && !did_emsg)
        emsg(_(e_trailing));
 
     /*
@@ -3386,7 +3391,7 @@ def_function(exarg_T *eap, char_u *name_arg)
     fp->uf_varargs = varargs;
     if (sandbox)
        flags |= FC_SANDBOX;
-    if (in_vim9script() && !ASCII_ISUPPER(*fp->uf_name))
+    if (vim9script && !ASCII_ISUPPER(*fp->uf_name))
        flags |= FC_VIM9;
     fp->uf_flags = flags;
     fp->uf_calls = 0;
index e4e70243b63e131b095752bb231f71e5381d250c..1ab604036ba3e9df82fd8a2707d2a24d54a41ace 100644 (file)
@@ -754,6 +754,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1268,
 /**/
     1267,
 /**/