Patch 8.2.4572
Problem:    Vim9: return type "any" is sometimes changed to first returned
            type.  (Virginia Senioria)
Solution:   Do not change the return type if declared as "any". (closes #9949)
Files:      src/vim9cmds.c, src/testdir/test_vim9_func.vim


*** ../vim-8.2.4571/src/vim9cmds.c      2022-03-12 14:51:12.765797435 +0000
--- src/vim9cmds.c      2022-03-15 12:14:13.718302120 +0000
***************
*** 2258,2265 ****
            // return type here.
            stack_type = get_type_on_stack(cctx, 0);
            if ((check_return_type && (cctx->ctx_ufunc->uf_ret_type == NULL
!                               || cctx->ctx_ufunc->uf_ret_type == &t_unknown
!                               || cctx->ctx_ufunc->uf_ret_type == &t_any))
                    || (!check_return_type
                                && cctx->ctx_ufunc->uf_ret_type == &t_unknown))
            {
--- 2258,2264 ----
            // return type here.
            stack_type = get_type_on_stack(cctx, 0);
            if ((check_return_type && (cctx->ctx_ufunc->uf_ret_type == NULL
!                               || cctx->ctx_ufunc->uf_ret_type == &t_unknown))
                    || (!check_return_type
                                && cctx->ctx_ufunc->uf_ret_type == &t_unknown))
            {
*** ../vim-8.2.4571/src/testdir/test_vim9_func.vim      2022-03-12 
21:28:18.532257720 +0000
--- src/testdir/test_vim9_func.vim      2022-03-15 12:26:03.569478456 +0000
***************
*** 535,540 ****
--- 535,564 ----
    v9.CheckScriptSuccess(lines)
  enddef
  
+ def Test_return_any_two_types()
+   var lines =<< trim END
+       vim9script
+ 
+       def G(Fn: func(string): any)
+         g:result = Fn("hello")
+       enddef
+ 
+       def F(a: number, b: string): any
+         echo b
+         if a > 0
+           return 1
+         else
+           return []
+         endif
+       enddef
+ 
+       G(function(F, [1]))
+   END
+   v9.CheckScriptSuccess(lines)
+   assert_equal(1, g:result)
+   unlet g:result
+ enddef
+ 
  func s:Increment()
    let g:counter += 1
  endfunc
*** ../vim-8.2.4571/src/version.c       2022-03-15 12:00:18.243752058 +0000
--- src/version.c       2022-03-15 12:15:26.810166064 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4572,
  /**/

-- 
Two fish in a tank. One says to the other:
"Do you know how to drive this thing?"

 /// 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/20220315122914.528341C42FC%40moolenaar.net.

Raspunde prin e-mail lui