Patch 9.0.0156
Problem:    Giving E1170 only in an expression is confusing.
Solution:   Give E1170 for any "#{ comment". (closes #10855)
Files:      src/errors.h, src/vim9script.c, src/eval.c, src/ex_docmd.c,
            src/testdir/test_vim9_script.vim


*** ../vim-9.0.0155/src/errors.h        2022-08-06 11:35:24.888762716 +0100
--- src/errors.h        2022-08-06 17:52:39.613928309 +0100
***************
*** 2984,2991 ****
        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_missing_end_block[]
        INIT(= N_("E1171: Missing } after inline function"));
  EXTERN char e_cannot_use_default_values_in_lambda[]
--- 2984,2991 ----
        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[]
!       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[]
*** ../vim-9.0.0155/src/vim9script.c    2022-08-06 11:35:24.888762716 +0100
--- src/vim9script.c    2022-08-06 17:52:43.289915299 +0100
***************
*** 176,191 ****
  }
  
  /*
!  * Give an error message if "p" points at "#{" and return TRUE.
   * 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] != '{')
      {
!       emsg(_(e_cannot_use_hash_curly_to_start_comment_in_an_expression));
        return TRUE;
      }
      return FALSE;
--- 176,193 ----
  }
  
  /*
!  * 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 (p[0] == '#' && p[1] == '{' && p[2] != '{')
      {
!       if (!did_emsg)
!           emsg(_(e_cannot_use_hash_curly_to_start_comment));
        return TRUE;
      }
      return FALSE;
***************
*** 194,205 ****
  
  /*
   * Return TRUE if "p" points at a "#" not followed by one '{'.
   * Does not check for white space.
   */
      int
  vim9_comment_start(char_u *p)
  {
!     return p[0] == '#' && (p[1] != '{' || p[2] == '{');
  }
  
  #if defined(FEAT_EVAL) || defined(PROTO)
--- 196,208 ----
  
  /*
   * 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] == '#' && !vim9_bad_comment(p);
  }
  
  #if defined(FEAT_EVAL) || defined(PROTO)
*** ../vim-9.0.0155/src/eval.c  2022-08-06 11:35:24.888762716 +0100
--- src/eval.c  2022-08-06 17:55:45.929308508 +0100
***************
*** 2157,2164 ****
                    break;
            p = nl;
        }
-       else if (vim9_bad_comment(p))
-           break;
        if (*p != NL)
            break;
        ++p;  // skip another NL
--- 2157,2162 ----
***************
*** 2184,2193 ****
            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;
      }
--- 2182,2188 ----
*** ../vim-9.0.0155/src/ex_docmd.c      2022-07-06 13:31:25.295370106 +0100
--- src/ex_docmd.c      2022-08-06 18:07:09.907450674 +0100
***************
*** 2842,2849 ****
                if (eap->nextcmd != NULL)
                    ++eap->nextcmd;
            }
!           if (vim9script && has_cmdmod(cmod, FALSE))
!               *errormsg = _(e_command_modifier_without_command);
            return FAIL;
        }
        if (*eap->cmd == NUL)
--- 2842,2855 ----
                if (eap->nextcmd != NULL)
                    ++eap->nextcmd;
            }
!           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)
*** ../vim-9.0.0155/src/testdir/test_vim9_script.vim    2022-07-26 
15:10:52.813542580 +0100
--- src/testdir/test_vim9_script.vim    2022-08-06 17:59:04.768717072 +0100
***************
*** 2668,2675 ****
        'vim9script',
        '# something',
        '#something',
!       '#{something',
        ])
  
    split Xfile
    v9.CheckScriptSuccess([
--- 2668,2679 ----
        'vim9script',
        '# something',
        '#something',
!       '#{{something',
        ])
+   v9.CheckScriptFailure([
+       'vim9script',
+       '#{something',
+       ], 'E1170:')
  
    split Xfile
    v9.CheckScriptSuccess([
*** ../vim-9.0.0155/src/version.c       2022-08-06 17:38:47.120785704 +0100
--- src/version.c       2022-08-06 18:11:38.418808123 +0100
***************
*** 737,738 ****
--- 737,740 ----
  {   /* Add new patch number below this line */
+ /**/
+     156,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
258. When you want to see your girlfriend, you surf to her homepage.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220806171247.5FF0B1C0EC3%40moolenaar.net.

Raspunde prin e-mail lui