Patch 8.2.1739
Problem:    Vim9: crash when compiling a manually defined function. (Antony
            Scriven)
Solution:   Check that the script ID is positive. (closes #7012)
Files:      src/vim9compile.c, src/testdir/test_vim9_script.vim


*** ../vim-8.2.1738/src/vim9compile.c   2020-09-23 21:57:16.641934712 +0200
--- src/vim9compile.c   2020-09-25 21:40:36.886516508 +0200
***************
*** 277,285 ****
  lookup_script(char_u *name, size_t len, int vim9script)
  {
      int                   cc;
!     hashtab_T     *ht = &SCRIPT_VARS(current_sctx.sc_sid);
      dictitem_T            *di;
  
      if (vim9script && !script_is_vim9())
        return FAIL;
      cc = name[len];
--- 277,288 ----
  lookup_script(char_u *name, size_t len, int vim9script)
  {
      int                   cc;
!     hashtab_T     *ht;
      dictitem_T            *di;
  
+     if (current_sctx.sc_sid <= 0)
+       return FAIL;
+     ht = &SCRIPT_VARS(current_sctx.sc_sid);
      if (vim9script && !script_is_vim9())
        return FAIL;
      cc = name[len];
*** ../vim-8.2.1738/src/testdir/test_vim9_script.vim    2020-09-21 
22:21:15.167008475 +0200
--- src/testdir/test_vim9_script.vim    2020-09-25 21:44:56.357519201 +0200
***************
*** 2755,2761 ****
      exe 'set rtp^=' .. getcwd() .. '/Xruntime'
      call crash#func()
      call writefile(['ok'], 'Xdidit')
!     qall
    END
    writefile(lines, 'Xscript')
    RunVim([], [], '-S Xscript')
--- 2755,2761 ----
      exe 'set rtp^=' .. getcwd() .. '/Xruntime'
      call crash#func()
      call writefile(['ok'], 'Xdidit')
!     qall!
    END
    writefile(lines, 'Xscript')
    RunVim([], [], '-S Xscript')
***************
*** 2817,2823 ****
  def Test_invalid_sid()
    assert_fails('func <SNR>1234_func', 'E123:')
  
!   if RunVim([], ['wq Xdidit'], '+"func <SNR>1_func"')
      assert_equal([], readfile('Xdidit'))
    endif
    delete('Xdidit')
--- 2817,2823 ----
  def Test_invalid_sid()
    assert_fails('func <SNR>1234_func', 'E123:')
  
!   if RunVim([], ['wq! Xdidit'], '+"func <SNR>1_func"')
      assert_equal([], readfile('Xdidit'))
    endif
    delete('Xdidit')
***************
*** 2831,2836 ****
--- 2831,2857 ----
    CheckDefAndScriptSuccess(lines)
  enddef
  
+ def Test_define_func_at_command_line()
+   # run in a separate Vim instance to avoid the script context
+   let lines =<< trim END
+     func CheckAndQuit()
+       call assert_fails('call Afunc()', 'E117: Unknown function: Bfunc')
+       call writefile(['errors: ' .. string(v:errors)], 'Xdidcmd')
+     endfunc
+   END
+   writefile([''], 'Xdidcmd')
+   writefile(lines, 'XcallFunc')
+   let buf = RunVimInTerminal('-S XcallFunc', #{rows: 6})
+   # define Afunc() on the command line
+   term_sendkeys(buf, ":def Afunc()\<CR>Bfunc()\<CR>enddef\<CR>")
+   term_sendkeys(buf, ":call CheckAndQuit()\<CR>")
+   WaitForAssert({-> assert_equal(['errors: []'], readfile('Xdidcmd'))})
+ 
+   call StopVimInTerminal(buf)
+   delete('XcallFunc')
+   delete('Xdidcmd')
+ enddef
+ 
  " Keep this last, it messes up highlighting.
  def Test_substitute_cmd()
    new
*** ../vim-8.2.1738/src/version.c       2020-09-24 23:08:11.132478783 +0200
--- src/version.c       2020-09-25 21:46:31.385186932 +0200
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     1739,
  /**/

-- 
For humans, honesty is a matter of degree.  Engineers are always honest in
matters of technology and human relationships.  That's why it's a good idea
to keep engineers away from customers, romantic interests, and other people
who can't handle the truth.
                                (Scott Adams - The Dilbert principle)

 /// 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/202009251947.08PJlskl556291%40masaka.moolenaar.net.

Raspunde prin e-mail lui