Patch 8.2.2527
Problem:    Vim9: lambda return type is not determined at script level.
Solution:   Compile the lambda to get the return type. (closes #7843)
Files:      src/eval.c, src/vim.h, src/vim9.h,
            src/testdir/test_vim9_assign.vim


*** ../vim-8.2.2526/src/eval.c  2021-02-11 21:19:30.522147936 +0100
--- src/eval.c  2021-02-17 16:55:17.020507678 +0100
***************
*** 3421,3427 ****
--- 3421,3437 ----
       */
      case '(': ret = NOTDONE;
                if (in_vim9script())
+               {
                    ret = get_lambda_tv(arg, rettv, TRUE, evalarg);
+                   if (ret == OK && evaluate)
+                   {
+                       ufunc_T *ufunc = rettv->vval.v_partial->pt_func;
+ 
+                       // compile it here to get the return type
+                       compile_def_function(ufunc,
+                                                TRUE, PROFILING(ufunc), NULL);
+                   }
+               }
                if (ret == NOTDONE)
                {
                    *arg = skipwhite_and_linebreak(*arg + 1, evalarg);
*** ../vim-8.2.2526/src/vim.h   2021-02-10 19:22:12.132400451 +0100
--- src/vim.h   2021-02-17 16:45:54.877966979 +0100
***************
*** 1787,1792 ****
--- 1787,1798 ----
  typedef int proftime_T;           // dummy for function prototypes
  #endif
  
+ #ifdef FEAT_PROFILE
+ # define PROFILING(ufunc) (do_profiling == PROF_YES && (ufunc)->uf_profiling)
+ #else
+ # define PROFILING(ufunc) FALSE
+ #endif
+ 
  /*
   * When compiling with 32 bit Perl time_t is 32 bits in the Perl code but 64
   * bits elsewhere.  That causes memory corruption.  Define time_T and use it
*** ../vim-8.2.2526/src/vim9.h  2021-02-13 15:02:43.063505534 +0100
--- src/vim9.h  2021-02-17 16:45:59.153955964 +0100
***************
*** 418,428 ****
  #define LNUM_VARIABLE_RANGE_ABOVE -888
  
  #ifdef FEAT_PROFILE
- # define PROFILING(ufunc) (do_profiling == PROF_YES && (ufunc)->uf_profiling)
  # define INSTRUCTIONS(dfunc) \
        ((do_profiling == PROF_YES && (dfunc->df_ufunc)->uf_profiling) \
        ? (dfunc)->df_instr_prof : (dfunc)->df_instr)
  #else
- # define PROFILING(ufunc) FALSE
  # define INSTRUCTIONS(dfunc) ((dfunc)->df_instr)
  #endif
--- 418,426 ----
*** ../vim-8.2.2526/src/testdir/test_vim9_assign.vim    2021-02-11 
21:19:30.526147922 +0100
--- src/testdir/test_vim9_assign.vim    2021-02-17 16:59:10.087898828 +0100
***************
*** 1108,1113 ****
--- 1108,1115 ----
        assert_equal(123, FuncRef_Func())
        var FuncRef_Any: any = () => 123
        assert_equal(123, FuncRef_Any())
+       var FuncRef_Number: func(): number = () => 321
+       assert_equal(321, FuncRef_Number())
    END
    CheckScriptSuccess(lines)
  
***************
*** 1115,1122 ****
        var Ref: func(number)
        Ref = (j) => !j
    END
!   CheckDefFailure(lines, 'E1012: Type mismatch; expected func(number) but got 
func(any): bool')
!   CheckScriptFailure(['vim9script'] + lines, 'E1012: Type mismatch; expected 
func(number) but got func(any): any')
  enddef
  
  def Test_heredoc()
--- 1117,1123 ----
        var Ref: func(number)
        Ref = (j) => !j
    END
!   CheckDefAndScriptFailure(lines, 'E1012: Type mismatch; expected 
func(number) but got func(any): bool')
  enddef
  
  def Test_heredoc()
*** ../vim-8.2.2526/src/version.c       2021-02-17 15:05:41.544996596 +0100
--- src/version.c       2021-02-17 16:59:37.859826177 +0100
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     2527,
  /**/

-- 
Be nice to your kids...  they'll be the ones choosing your nursing home.

 /// 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/202102171602.11HG2PPu2220622%40masaka.moolenaar.net.

Raspunde prin e-mail lui