Patch 8.2.0625
Problem:    Vim9: confusing error when calling unknown function.
Solution:   Give error while compiling.
Files:      src/vim9compile.c, src/vim9execute.c,
            src/testdir/test_vim9_func.vim


*** ../vim-8.2.0624/src/vim9compile.c   2020-04-23 17:07:26.972434270 +0200
--- src/vim9compile.c   2020-04-23 17:40:18.430122755 +0200
***************
*** 2463,2470 ****
        goto theend;
      }
  
!     // The function may be defined only later.  Need to figure out at runtime.
!     res = generate_UCALL(cctx, name, argcount);
  
  theend:
      vim_free(tofree);
--- 2463,2474 ----
        goto theend;
      }
  
!     // A global function may be defined only later.  Need to figure out at
!     // runtime.
!     if (STRNCMP(namebuf, "g:", 2) == 0)
!       res = generate_UCALL(cctx, name, argcount);
!     else
!       semsg(_(e_unknownfunc), namebuf);
  
  theend:
      vim_free(tofree);
*** ../vim-8.2.0624/src/vim9execute.c   2020-04-19 18:27:20.791953204 +0200
--- src/vim9execute.c   2020-04-23 17:52:31.253121000 +0200
***************
*** 460,472 ****
      if (call_by_name(name, argcount, ectx, iptr) == FAIL
                                          && called_emsg == called_emsg_before)
      {
!       // "name" may be a variable that is a funcref or partial
!       //    if find variable
!       //      call_partial()
!       //    else
!       //      semsg(_(e_unknownfunc), name);
!       emsg("call_eval_func(partial) not implemented yet");
!       return FAIL;
      }
      return OK;
  }
--- 460,479 ----
      if (call_by_name(name, argcount, ectx, iptr) == FAIL
                                          && called_emsg == called_emsg_before)
      {
!       dictitem_T      *v;
! 
!       v = find_var(name, NULL, FALSE);
!       if (v == NULL)
!       {
!           semsg(_(e_unknownfunc), name);
!           return FAIL;
!       }
!       if (v->di_tv.v_type != VAR_PARTIAL && v->di_tv.v_type != VAR_FUNC)
!       {
!           semsg(_(e_unknownfunc), name);
!           return FAIL;
!       }
!       return call_partial(&v->di_tv, argcount, ectx);
      }
      return OK;
  }
*** ../vim-8.2.0624/src/testdir/test_vim9_func.vim      2020-04-13 
17:20:56.174130307 +0200
--- src/testdir/test_vim9_func.vim      2020-04-23 18:11:51.791563545 +0200
***************
*** 193,202 ****
  enddef
  
  def Test_call_func_defined_later()
!   call assert_equal('one', DefinedLater('one'))
    call assert_fails('call NotDefined("one")', 'E117:')
  enddef
  
  def CombineFuncrefTypes()
    " same arguments, different return type
    let Ref1: func(bool): string
--- 193,215 ----
  enddef
  
  def Test_call_func_defined_later()
!   call assert_equal('one', g:DefinedLater('one'))
    call assert_fails('call NotDefined("one")', 'E117:')
  enddef
  
+ func DefinedLater(arg)
+   return a:arg
+ endfunc
+ 
+ def Test_call_funcref()
+   assert_equal(3, g:SomeFunc('abc'))
+   assert_fails('NotAFunc()', 'E117:')
+   assert_fails('g:NotAFunc()', 'E117:')
+ enddef
+ 
+ let SomeFunc = function('len')
+ let NotAFunc = 'text'
+ 
  def CombineFuncrefTypes()
    " same arguments, different return type
    let Ref1: func(bool): string
***************
*** 217,228 ****
    Refb3 = g:cond ? Refb1 : Refb2
  enddef
  
- func DefinedLater(arg)
-   return a:arg
- endfunc
- 
  def FuncWithForwardCall()
!   return DefinedEvenLater("yes")
  enddef
  
  def DefinedEvenLater(arg: string): string
--- 230,237 ----
    Refb3 = g:cond ? Refb1 : Refb2
  enddef
  
  def FuncWithForwardCall()
!   return g:DefinedEvenLater("yes")
  enddef
  
  def DefinedEvenLater(arg: string): string
***************
*** 372,380 ****
    so Xdef
    call delete('Xdef')
  
!   call assert_equal(0, Func0())
!   call assert_equal('Func1', Func1())
!   call assert_equal('Func2', Func2())
  
    delfunc! Func0
    delfunc! Func1
--- 381,389 ----
    so Xdef
    call delete('Xdef')
  
!   call assert_equal(0, g:Func0())
!   call assert_equal('Func1', g:Func1())
!   call assert_equal('Func2', g:Func2())
  
    delfunc! Func0
    delfunc! Func1
*** ../vim-8.2.0624/src/version.c       2020-04-23 17:07:26.972434270 +0200
--- src/version.c       2020-04-23 18:12:59.939259822 +0200
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     625,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
4. Your eyeglasses have a web site burned in on them.

 /// 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/202004231614.03NGESMn009613%40masaka.moolenaar.net.

Raspunde prin e-mail lui