Patch 8.2.4554
Problem:    Vim9: using null values not sufficiently tested.
Solution:   Add more tests.  Fix uncovered problem.
Files:      src/vim9type.c, src/testdir/test_vim9_assign.vim,
            src/testdir/test_vim9_func.vim


*** ../vim-8.2.4553/src/vim9type.c      2022-03-08 19:43:51.688198945 +0000
--- src/vim9type.c      2022-03-12 21:22:22.004445141 +0000
***************
*** 1235,1240 ****
--- 1235,1253 ----
        {
            type_T *common;
  
+           // When one of the types is t_func_unknown return the other one.
+           // Useful if a list or dict item is null_func.
+           if (type1 == &t_func_unknown)
+           {
+               *dest = type2;
+               return;
+           }
+           if (type2 == &t_func_unknown)
+           {
+               *dest = type1;
+               return;
+           }
+ 
            common_type(type1->tt_member, type2->tt_member, &common, type_gap);
            if (type1->tt_argcount == type2->tt_argcount
                                                    && type1->tt_argcount >= 0)
*** ../vim-8.2.4553/src/testdir/test_vim9_assign.vim    2022-03-09 
19:46:43.161299056 +0000
--- src/testdir/test_vim9_assign.vim    2022-03-12 21:26:40.632322476 +0000
***************
*** 342,347 ****
--- 342,363 ----
        endif
  
        var d: dict<func> = {a: function('tr'), b: null_function}
+ 
+       var bl: list<blob> = [0z12, null_blob]
+       var dnl: list<dict<number>> = [{a: 1}, null_dict]
+       var dsl: list<dict<string>> = [{a: 'x'}, null_dict]
+       var lnl: list<list<number>> = [[1], null_list]
+       var lsl: list<list<string>> = [['x'], null_list]
+       def Len(v: string): number
+         return len(v)
+       enddef
+       var Ffl: list<func(string): number> = [Len, null_function]
+       var Fpl: list<func(string): number> = [Len, null_partial]
+       var sl: list<string> = ['x', null_string]
+       if has('job')
+         var jl: list<job> = [null_job]
+         var cl: list<channel> = [null_channel]
+       endif
    END
    v9.CheckDefAndScriptSuccess(lines)
  enddef
*** ../vim-8.2.4553/src/testdir/test_vim9_func.vim      2022-03-11 
18:54:13.980670599 +0000
--- src/testdir/test_vim9_func.vim      2022-03-12 20:48:41.598096539 +0000
***************
*** 3759,3764 ****
--- 3759,3872 ----
    v9.CheckScriptFailure(lines + ['echo H(G(F2))'], 'E1013:')
  enddef
  
+ def Test_call_func_with_null()
+   var lines =<< trim END
+       def Fstring(v: string)
+         assert_equal(null_string, v)
+       enddef
+       Fstring(null_string)
+       def Fblob(v: blob)
+         assert_equal(null_blob, v)
+       enddef
+       Fblob(null_blob)
+       def Flist(v: list<number>)
+         assert_equal(null_list, v)
+       enddef
+       Flist(null_list)
+       def Fdict(v: dict<number>)
+         assert_equal(null_dict, v)
+       enddef
+       Fdict(null_dict)
+       def Ffunc(Fv: func(number): number)
+         assert_equal(null_function, Fv)
+       enddef
+       Ffunc(null_function)
+       if has('channel')
+         def Fchannel(v: channel)
+           assert_equal(null_channel, v)
+         enddef
+         Fchannel(null_channel)
+         def Fjob(v: job)
+           assert_equal(null_job, v)
+         enddef
+         Fjob(null_job)
+       endif
+   END
+   v9.CheckDefAndScriptSuccess(lines)
+ enddef
+ 
+ def Test_null_default_argument()
+   var lines =<< trim END
+       def Fstring(v: string = null_string)
+         assert_equal(null_string, v)
+       enddef
+       Fstring()
+       def Fblob(v: blob = null_blob)
+         assert_equal(null_blob, v)
+       enddef
+       Fblob()
+       def Flist(v: list<number> = null_list)
+         assert_equal(null_list, v)
+       enddef
+       Flist()
+       def Fdict(v: dict<number> = null_dict)
+         assert_equal(null_dict, v)
+       enddef
+       Fdict()
+       def Ffunc(Fv: func(number): number = null_function)
+         assert_equal(null_function, Fv)
+       enddef
+       Ffunc()
+       if has('channel')
+         def Fchannel(v: channel = null_channel)
+           assert_equal(null_channel, v)
+         enddef
+         Fchannel()
+         def Fjob(v: job = null_job)
+           assert_equal(null_job, v)
+         enddef
+         Fjob()
+       endif
+   END
+   v9.CheckDefAndScriptSuccess(lines)
+ enddef
+ 
+ def Test_null_return()
+   var lines =<< trim END
+       def Fstring(): string
+         return null_string
+       enddef
+       assert_equal(null_string, Fstring())
+       def Fblob(): blob
+         return null_blob
+       enddef
+       assert_equal(null_blob, Fblob())
+       def Flist(): list<number>
+         return null_list
+       enddef
+       assert_equal(null_list, Flist())
+       def Fdict(): dict<number>
+         return null_dict
+       enddef
+       assert_equal(null_dict, Fdict())
+       def Ffunc(): func(number): number
+         return null_function
+       enddef
+       assert_equal(null_function, Ffunc())
+       if has('channel')
+         def Fchannel(): channel
+           return null_channel
+         enddef
+         assert_equal(null_channel, Fchannel())
+         def Fjob(): job
+           return null_job
+         enddef
+         assert_equal(null_job, Fjob())
+       endif
+   END
+   v9.CheckDefAndScriptSuccess(lines)
+ enddef
+ 
  def Test_list_any_type_checked()
    var lines =<< trim END
        vim9script
*** ../vim-8.2.4553/src/version.c       2022-03-12 17:38:26.354365193 +0000
--- src/version.c       2022-03-12 20:37:19.818571324 +0000
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     4554,
  /**/

-- 
"Marriage is when a man and woman become as one; the trouble starts
when they try to decide which one"

 /// Bram Moolenaar -- b...@moolenaar.net -- 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 vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20220312212851.5ACDC1C79E4%40moolenaar.net.

Raspunde prin e-mail lui