1
0
forked from aniani/vim

patch 8.2.4554: Vim9: using null values not sufficiently tested

Problem:    Vim9: using null values not sufficiently tested.
Solution:   Add more tests.  Fix uncovered problem.
This commit is contained in:
Bram Moolenaar
2022-03-12 21:28:22 +00:00
parent 8b530b3158
commit badf04f5c2
4 changed files with 139 additions and 0 deletions

View File

@@ -342,6 +342,22 @@ def Test_null_values()
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

View File

@@ -3759,6 +3759,114 @@ def Test_check_func_arg_types()
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

View File

@@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4554,
/**/
4553,
/**/

View File

@@ -1235,6 +1235,19 @@ common_type(type_T *type1, type_T *type2, type_T **dest, garray_T *type_gap)
{
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)