]> granicus.if.org Git - vim/commitdiff
patch 9.0.0156: giving E1170 only in an expression is confusing v9.0.0156
authorBram Moolenaar <Bram@vim.org>
Sat, 6 Aug 2022 17:12:06 +0000 (18:12 +0100)
committerBram Moolenaar <Bram@vim.org>
Sat, 6 Aug 2022 17:12:06 +0000 (18:12 +0100)
Problem:    Giving E1170 only in an expression is confusing.
Solution:   Give E1170 for any "#{ comment". (closes #10855)

src/errors.h
src/eval.c
src/ex_docmd.c
src/testdir/test_vim9_script.vim
src/version.c
src/vim9script.c

index 977abbf1417d106ee74e27e76196b24bd4434223..3b23c88adbd4c8598eb2de77805c7ba61d3772b8 100644 (file)
@@ -2984,8 +2984,8 @@ EXTERN char e_argument_already_declared_in_script_str[]
        INIT(= N_("E1168: Argument already declared in the script: %s"));
 EXTERN char e_expression_too_recursive_str[]
        INIT(= N_("E1169: Expression too recursive: %s"));
-EXTERN char e_cannot_use_hash_curly_to_start_comment_in_an_expression[]
-       INIT(= N_("E1170: Cannot use #{ to start a comment in an expression"));
+EXTERN char e_cannot_use_hash_curly_to_start_comment[]
+       INIT(= N_("E1170: Cannot use #{ to start a comment"));
 EXTERN char e_missing_end_block[]
        INIT(= N_("E1171: Missing } after inline function"));
 EXTERN char e_cannot_use_default_values_in_lambda[]
index 8dfbb8f2a329e8e2c85910eda216c097443dbc4d..42b883e9b00bd3e86af7d06d3c192781c84fe051 100644 (file)
@@ -2157,8 +2157,6 @@ newline_skip_comments(char_u *arg)
                    break;
            p = nl;
        }
-       else if (vim9_bad_comment(p))
-           break;
        if (*p != NL)
            break;
        ++p;  // skip another NL
@@ -2184,10 +2182,7 @@ getline_peek_skip_comments(evalarg_T *evalarg)
            break;
        p = skipwhite(next);
        if (*p != NUL && !vim9_comment_start(p))
-       {
-           (void)vim9_bad_comment(p);
            return next;
-       }
        if (eval_next_line(NULL, evalarg) == NULL)
            break;
     }
index fad0bdacafc66809eaa7d5be9110a6e88b3ff5fd..d8a724393b7f0992682c0c4dca3a45ac2d7d4305 100644 (file)
@@ -2842,8 +2842,14 @@ parse_command_modifiers(
                if (eap->nextcmd != NULL)
                    ++eap->nextcmd;
            }
-           if (vim9script && has_cmdmod(cmod, FALSE))
-               *errormsg = _(e_command_modifier_without_command);
+           if (vim9script)
+           {
+               if (has_cmdmod(cmod, FALSE))
+                   *errormsg = _(e_command_modifier_without_command);
+               if (eap->cmd[0] == '#' && eap->cmd[1] == '{'
+                                                        && eap->cmd[2] != '{')
+                   *errormsg = _(e_cannot_use_hash_curly_to_start_comment);
+           }
            return FAIL;
        }
        if (*eap->cmd == NUL)
index 98a4590c24e10993dead826599f193f2b3802c39..3199ac3953740e6711b4f2309a587589a924b715 100644 (file)
@@ -2668,8 +2668,12 @@ def Test_vim9_comment()
       'vim9script',
       '# something',
       '#something',
-      '#{something',
+      '#{{something',
       ])
+  v9.CheckScriptFailure([
+      'vim9script',
+      '#{something',
+      ], 'E1170:')
 
   split Xfile
   v9.CheckScriptSuccess([
index b75d722a687828127168334942c7918e433975e4..196f3e68ab68f845909a5bbcb29e99435e0e5cca 100644 (file)
@@ -735,6 +735,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    156,
 /**/
     155,
 /**/
index e3cb992e4e5e7f7f5c3a211aaf39db2e2179a0d0..e9c9b2c7dca6e4c9d0f0531a5a894fafc2d4b6d3 100644 (file)
@@ -176,16 +176,18 @@ not_in_vim9(exarg_T *eap)
 }
 
 /*
- * Give an error message if "p" points at "#{" and return TRUE.
+ * Return TRUE if "p" points at "#{", not "#{{".
+ * Give an error message if not done already.
  * This avoids that using a legacy style #{} dictionary leads to difficult to
  * understand errors.
  */
     int
 vim9_bad_comment(char_u *p)
 {
-    if (!did_emsg && p[0] == '#' && p[1] == '{' && p[2] != '{')
+    if (p[0] == '#' && p[1] == '{' && p[2] != '{')
     {
-       emsg(_(e_cannot_use_hash_curly_to_start_comment_in_an_expression));
+       if (!did_emsg)
+           emsg(_(e_cannot_use_hash_curly_to_start_comment));
        return TRUE;
     }
     return FALSE;
@@ -194,12 +196,13 @@ vim9_bad_comment(char_u *p)
 
 /*
  * Return TRUE if "p" points at a "#" not followed by one '{'.
+ * Gives an error for using "#{", not for "#{{".
  * Does not check for white space.
  */
     int
 vim9_comment_start(char_u *p)
 {
-    return p[0] == '#' && (p[1] != '{' || p[2] == '{');
+    return p[0] == '#' && !vim9_bad_comment(p);
 }
 
 #if defined(FEAT_EVAL) || defined(PROTO)