Patch 8.2.0992
Problem:    Vim9: crash when using :import in the Vim command.
Solution:   Give an error when using :import outside of a script.
            (closes #6271)
Files:      src/vim9script.c, src/testdir/test_vim9_script.vim,
            src/testdir/term_util.vim


*** ../vim-8.2.0991/src/vim9script.c    2020-06-14 12:50:20.955092700 +0200
--- src/vim9script.c    2020-06-16 23:17:27.972798529 +0200
***************
*** 32,44 ****
      void
  ex_vim9script(exarg_T *eap)
  {
!     scriptitem_T    *si = SCRIPT_ITEM(current_sctx.sc_sid);
  
      if (!getline_equal(eap->getline, eap->cookie, getsourceline))
      {
        emsg(_("E1038: vim9script can only be used in a script"));
        return;
      }
      if (si->sn_had_command)
      {
        emsg(_("E1039: vim9script must be the first command in a script"));
--- 32,45 ----
      void
  ex_vim9script(exarg_T *eap)
  {
!     scriptitem_T    *si;
  
      if (!getline_equal(eap->getline, eap->cookie, getsourceline))
      {
        emsg(_("E1038: vim9script can only be used in a script"));
        return;
      }
+     si = SCRIPT_ITEM(current_sctx.sc_sid);
      if (si->sn_had_command)
      {
        emsg(_("E1039: vim9script must be the first command in a script"));
***************
*** 141,148 ****
      void
  ex_import(exarg_T *eap)
  {
!     char_u *cmd_end = handle_import(eap->arg, NULL, current_sctx.sc_sid, 
NULL);
  
      if (cmd_end != NULL)
        eap->nextcmd = check_nextcmd(cmd_end);
  }
--- 142,156 ----
      void
  ex_import(exarg_T *eap)
  {
!     char_u *cmd_end;
  
+     if (!getline_equal(eap->getline, eap->cookie, getsourceline))
+     {
+       emsg(_("E1094: import can only be used in a script"));
+       return;
+     }
+ 
+     cmd_end = handle_import(eap->arg, NULL, current_sctx.sc_sid, NULL);
      if (cmd_end != NULL)
        eap->nextcmd = check_nextcmd(cmd_end);
  }
*** ../vim-8.2.0991/src/testdir/test_vim9_script.vim    2020-06-16 
11:34:38.314223444 +0200
--- src/testdir/test_vim9_script.vim    2020-06-16 23:16:07.105189421 +0200
***************
*** 1,6 ****
--- 1,7 ----
  " Test various aspects of the Vim9 script language.
  
  source check.vim
+ source term_util.vim
  source view_util.vim
  source vim9.vim
  
***************
*** 777,782 ****
--- 778,802 ----
    assert_fails('export something', 'E1043')
  enddef
  
+ def Test_import_fails_without_script()
+   CheckRunVimInTerminal
+ 
+   let export =<< trim END
+     vim9script
+     export def Foo(): number
+         return 0
+     enddef
+   END
+   writefile(export, 'Xexport.vim')
+ 
+   let buf = RunVimInTerminal('-c "import Foo from ''./Xexport.vim''"', #{
+                 rows: 6, wait_for_ruler: 0})
+   WaitForAssert({-> assert_match('^E1094:', term_getline(buf, 5))})
+ 
+   delete('Xexport.vim')
+   StopVimInTerminal(buf)
+ enddef
+ 
  def Test_vim9script_reload_import()
    let lines =<< trim END
      vim9script
*** ../vim-8.2.0991/src/testdir/term_util.vim   2020-06-09 15:57:32.929019414 
+0200
--- src/testdir/term_util.vim   2020-06-16 23:15:01.577511290 +0200
***************
*** 107,122 ****
  
    call TermWait(buf)
  
!   " Wait for "All" or "Top" of the ruler to be shown in the last line or in
!   " the status line of the last window. This can be quite slow (e.g. when
!   " using valgrind).
!   " If it fails then show the terminal contents for debugging.
!   try
!     call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || 
len(term_getline(buf, rows - statusoff)) >= cols - 1})
!   catch /timed out after/
!     let lines = map(range(1, rows), {key, val -> term_getline(buf, val)})
!     call assert_report('RunVimInTerminal() failed, screen contents: ' . 
join(lines, "<NL>"))
!   endtry
  
    " Starting a terminal to run Vim is always considered flaky.
    let g:test_is_flaky = 1
--- 107,124 ----
  
    call TermWait(buf)
  
!   if get(a:options, 'wait_for_ruler', 1)
!     " Wait for "All" or "Top" of the ruler to be shown in the last line or in
!     " the status line of the last window. This can be quite slow (e.g. when
!     " using valgrind).
!     " If it fails then show the terminal contents for debugging.
!     try
!       call WaitFor({-> len(term_getline(buf, rows)) >= cols - 1 || 
len(term_getline(buf, rows - statusoff)) >= cols - 1})
!     catch /timed out after/
!       let lines = map(range(1, rows), {key, val -> term_getline(buf, val)})
!       call assert_report('RunVimInTerminal() failed, screen contents: ' . 
join(lines, "<NL>"))
!     endtry
!   endif
  
    " Starting a terminal to run Vim is always considered flaky.
    let g:test_is_flaky = 1
*** ../vim-8.2.0991/src/version.c       2020-06-16 22:42:01.069306175 +0200
--- src/version.c       2020-06-16 23:03:53.264646345 +0200
***************
*** 756,757 ****
--- 756,759 ----
  {   /* Add new patch number below this line */
+ /**/
+     992,
  /**/

-- 
BLACK KNIGHT:  Come on you pansy!
    [hah] [parry thrust]
    [ARTHUR chops the BLACK KNIGHT's right arm off]
ARTHUR:        Victory is mine!  [kneeling]
               We thank thee Lord, that in thy merc-
    [Black Knight kicks Arthur in the head while he is praying]
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            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/202006162121.05GLLScg1458734%40masaka.moolenaar.net.

Raspunde prin e-mail lui