Patch 8.2.3924
Problem:    Vim9: no error if something follows :enddef in a nested function.
Solution:   Give an error.  Move common code to a function.
Files:      src/userfunc.c, src/vim9compile.c, src/errors.h,
            src/testdir/test_vim9_func.vim


*** ../vim-8.2.3923/src/userfunc.c      2021-12-28 17:23:08.910865519 +0000
--- src/userfunc.c      2021-12-28 17:52:16.864088239 +0000
***************
*** 166,171 ****
--- 166,200 ----
  }
  
  /*
+  * Handle line continuation in function arguments or body.
+  * Get a next line, store it in "eap" if appropriate and use "line_to_free" to
+  * handle freeing the line later.
+  */
+     static char_u *
+ get_function_line(
+       exarg_T         *eap,
+       char_u          **line_to_free,
+       getline_opt_T   getline_options,
+       int             indent)
+ {
+     char_u *theline;
+ 
+     if (eap->getline == NULL)
+       theline = getcmdline(':', 0L, indent, getline_options);
+     else
+       theline = eap->getline(':', eap->cookie, indent, getline_options);
+     if (theline != NULL)
+     {
+       if (*eap->cmdlinep == *line_to_free)
+           *eap->cmdlinep = theline;
+       vim_free(*line_to_free);
+       *line_to_free = theline;
+     }
+ 
+     return theline;
+ }
+ 
+ /*
   * Get function arguments.
   * "argp" should point to just after the "(", possibly to white space.
   * "argp" is advanced just after "endchar".
***************
*** 212,227 ****
        while (eap != NULL && eap->getline != NULL
                         && (*p == NUL || (VIM_ISWHITE(*whitep) && *p == '#')))
        {
-           char_u *theline;
- 
            // End of the line, get the next one.
!           theline = eap->getline(':', eap->cookie, 0, TRUE);
            if (theline == NULL)
                break;
-           vim_free(*line_to_free);
-           if (*eap->cmdlinep == *line_to_free)
-               *eap->cmdlinep = theline;
-           *line_to_free = theline;
            whitep = (char_u *)" ";
            p = skipwhite(theline);
        }
--- 241,251 ----
        while (eap != NULL && eap->getline != NULL
                         && (*p == NUL || (VIM_ISWHITE(*whitep) && *p == '#')))
        {
            // End of the line, get the next one.
!           char_u *theline = get_function_line(eap, line_to_free, 0, TRUE);
! 
            if (theline == NULL)
                break;
            whitep = (char_u *)" ";
            p = skipwhite(theline);
        }
***************
*** 720,734 ****
        }
        else
        {
!           if (eap->getline == NULL)
!               theline = getcmdline(':', 0L, indent, getline_options);
!           else
!               theline = eap->getline(':', eap->cookie, indent,
                                                              getline_options);
-           if (*eap->cmdlinep == *line_to_free)
-               *eap->cmdlinep = theline;
-           vim_free(*line_to_free);
-           *line_to_free = theline;
        }
        if (KeyTyped)
            lines_left = Rows - 1;
--- 744,751 ----
        }
        else
        {
!           theline = get_function_line(eap, line_to_free, indent,
                                                              getline_options);
        }
        if (KeyTyped)
            lines_left = Rows - 1;
***************
*** 827,833 ****
                        SOURCING_LNUM = sourcing_lnum_top
                                                        + newlines->ga_len + 1;
                        if (eap->cmdidx == CMD_def)
!                           semsg(_(e_text_found_after_enddef_str), p);
                        else
                            give_warning2((char_u *)
                                   _("W22: Text found after :endfunction: %s"),
--- 844,850 ----
                        SOURCING_LNUM = sourcing_lnum_top
                                                        + newlines->ga_len + 1;
                        if (eap->cmdidx == CMD_def)
!                           semsg(_(e_text_found_after_str_str), "enddef", p);
                        else
                            give_warning2((char_u *)
                                   _("W22: Text found after :endfunction: %s"),
*** ../vim-8.2.3923/src/vim9compile.c   2021-12-26 14:22:55.661931074 +0000
--- src/vim9compile.c   2021-12-28 17:50:05.036303865 +0000
***************
*** 879,890 ****
      }
  
      ufunc = define_function(eap, lambda_name, line_to_free);
- 
      if (ufunc == NULL)
      {
        r = eap->skip ? OK : FAIL;
        goto theend;
      }
  
      // copy over the block scope IDs before compiling
      if (!is_global && cctx->ctx_ufunc->uf_block_depth > 0)
--- 879,896 ----
      }
  
      ufunc = define_function(eap, lambda_name, line_to_free);
      if (ufunc == NULL)
      {
        r = eap->skip ? OK : FAIL;
        goto theend;
      }
+     if (eap->nextcmd != NULL)
+     {
+       semsg(_(e_text_found_after_str_str),
+             eap->cmdidx == CMD_def ? "enddef" : "endfunction", eap->nextcmd);
+       r = FAIL;
+       goto theend;
+     }
  
      // copy over the block scope IDs before compiling
      if (!is_global && cctx->ctx_ufunc->uf_block_depth > 0)
*** ../vim-8.2.3923/src/errors.h        2021-12-27 20:57:03.483387913 +0000
--- src/errors.h        2021-12-28 17:49:04.612402705 +0000
***************
*** 717,724 ****
        INIT(= N_("E1171: Missing } after inline function"));
  EXTERN char e_cannot_use_default_values_in_lambda[]
        INIT(= N_("E1172: Cannot use default values in a lambda"));
! EXTERN char e_text_found_after_enddef_str[]
!       INIT(= N_("E1173: Text found after enddef: %s"));
  EXTERN char e_string_required_for_argument_nr[]
        INIT(= N_("E1174: String required for argument %d"));
  EXTERN char e_non_empty_string_required_for_argument_nr[]
--- 717,724 ----
        INIT(= N_("E1171: Missing } after inline function"));
  EXTERN char e_cannot_use_default_values_in_lambda[]
        INIT(= N_("E1172: Cannot use default values in a lambda"));
! EXTERN char e_text_found_after_str_str[]
!       INIT(= N_("E1173: Text found after %s: %s"));
  EXTERN char e_string_required_for_argument_nr[]
        INIT(= N_("E1174: String required for argument %d"));
  EXTERN char e_non_empty_string_required_for_argument_nr[]
*** ../vim-8.2.3923/src/testdir/test_vim9_func.vim      2021-12-28 
17:23:08.910865519 +0000
--- src/testdir/test_vim9_func.vim      2021-12-28 17:54:26.091876772 +0000
***************
*** 1686,1692 ****
        # Compile all functions
        defcompile
    END
!   CheckScriptFailure(lines, 'E476: Invalid command: AAAAA')
  enddef
  
  def Test_nested_function_with_args_split()
--- 1686,1692 ----
        # Compile all functions
        defcompile
    END
!   CheckScriptFailure(lines, 'E1173: Text found after enddef: BBBB')
  enddef
  
  def Test_nested_function_with_args_split()
***************
*** 1703,1710 ****
        # Compile all functions
        defcompile
    END
!   # FIXME: this should fail on the BBBB
!   CheckScriptSuccess(lines)
  enddef
  
  def Test_return_type_wrong()
--- 1703,1719 ----
        # Compile all functions
        defcompile
    END
!   CheckScriptFailure(lines, 'E1173: Text found after enddef: BBBB')
! 
!   lines =<< trim END
!       vim9script
!       def FirstFunction()
!         func SecondFunction()
!         endfunc|BBBB
!       enddef
!       defcompile
!   END
!   CheckScriptFailure(lines, 'E1173: Text found after endfunction: BBBB')
  enddef
  
  def Test_return_type_wrong()
*** ../vim-8.2.3923/src/version.c       2021-12-28 17:23:08.910865519 +0000
--- src/version.c       2021-12-28 17:41:57.165099380 +0000
***************
*** 751,752 ****
--- 751,754 ----
  {   /* Add new patch number below this line */
+ /**/
+     3924,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
130. You can't get out of your desk even if it's time to eat or time
     to go to the bathroom.

 /// 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/20211228175646.923E11C0641%40moolenaar.net.

Raspunde prin e-mail lui