mirror of
https://github.com/vim/vim.git
synced 2025-10-18 07:54:29 -04:00
patch 8.2.3857: Vim9: inconsistent error for using function()
Problem: Vim9: inconsistent error for using function(). Solution: Use a runtime type check for the result of function(). (closes #8492)
This commit is contained in:
@@ -957,6 +957,11 @@ ret_func_any(int argcount UNUSED, type_T **argtypes UNUSED)
|
|||||||
return &t_func_any;
|
return &t_func_any;
|
||||||
}
|
}
|
||||||
static type_T *
|
static type_T *
|
||||||
|
ret_func_unknown(int argcount UNUSED, type_T **argtypes UNUSED)
|
||||||
|
{
|
||||||
|
return &t_func_unknown;
|
||||||
|
}
|
||||||
|
static type_T *
|
||||||
ret_channel(int argcount UNUSED, type_T **argtypes UNUSED)
|
ret_channel(int argcount UNUSED, type_T **argtypes UNUSED)
|
||||||
{
|
{
|
||||||
return &t_channel;
|
return &t_channel;
|
||||||
@@ -1065,8 +1070,6 @@ ret_maparg(int argcount, type_T **argtypes UNUSED)
|
|||||||
return &t_string;
|
return &t_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
static type_T *ret_f_function(int argcount, type_T **argtypes);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Array with names and number of arguments of all internal functions
|
* Array with names and number of arguments of all internal functions
|
||||||
* MUST BE KEPT SORTED IN strcmp() ORDER FOR BINARY SEARCH!
|
* MUST BE KEPT SORTED IN strcmp() ORDER FOR BINARY SEARCH!
|
||||||
@@ -1429,9 +1432,9 @@ static funcentry_T global_functions[] =
|
|||||||
{"fullcommand", 1, 1, FEARG_1, arg1_string,
|
{"fullcommand", 1, 1, FEARG_1, arg1_string,
|
||||||
ret_string, f_fullcommand},
|
ret_string, f_fullcommand},
|
||||||
{"funcref", 1, 3, FEARG_1, arg3_any_list_dict,
|
{"funcref", 1, 3, FEARG_1, arg3_any_list_dict,
|
||||||
ret_func_any, f_funcref},
|
ret_func_unknown, f_funcref},
|
||||||
{"function", 1, 3, FEARG_1, arg3_any_list_dict,
|
{"function", 1, 3, FEARG_1, arg3_any_list_dict,
|
||||||
ret_f_function, f_function},
|
ret_func_unknown, f_function},
|
||||||
{"garbagecollect", 0, 1, 0, arg1_bool,
|
{"garbagecollect", 0, 1, 0, arg1_bool,
|
||||||
ret_void, f_garbagecollect},
|
ret_void, f_garbagecollect},
|
||||||
{"get", 2, 3, FEARG_1, arg23_get,
|
{"get", 2, 3, FEARG_1, arg23_get,
|
||||||
@@ -4170,15 +4173,6 @@ f_funcref(typval_T *argvars, typval_T *rettv)
|
|||||||
common_function(argvars, rettv, TRUE);
|
common_function(argvars, rettv, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static type_T *
|
|
||||||
ret_f_function(int argcount, type_T **argtypes)
|
|
||||||
{
|
|
||||||
if (argcount == 1 && argtypes[0]->tt_type == VAR_STRING)
|
|
||||||
return &t_func_any;
|
|
||||||
// Need to check the type at runtime, the function may be defined later.
|
|
||||||
return &t_func_unknown;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "function()" function
|
* "function()" function
|
||||||
*/
|
*/
|
||||||
|
@@ -1258,7 +1258,7 @@ def Test_filter_missing_argument()
|
|||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_foldclosed()
|
def Test_foldclosed()
|
||||||
CheckDefAndScriptFailure(['foldclosed(function("min"))'], ['E1013: Argument 1: type mismatch, expected string but got func(...): any', 'E1220: String or Number required for argument 1'])
|
CheckDefAndScriptFailure(['foldclosed(function("min"))'], ['E1013: Argument 1: type mismatch, expected string but got func(...): unknown', 'E1220: String or Number required for argument 1'])
|
||||||
CheckDefExecAndScriptFailure(['foldclosed("")'], 'E1209: Invalid value for a line number')
|
CheckDefExecAndScriptFailure(['foldclosed("")'], 'E1209: Invalid value for a line number')
|
||||||
assert_equal(-1, foldclosed(1))
|
assert_equal(-1, foldclosed(1))
|
||||||
assert_equal(-1, foldclosed('$'))
|
assert_equal(-1, foldclosed('$'))
|
||||||
@@ -1312,11 +1312,69 @@ enddef
|
|||||||
def Test_funcref()
|
def Test_funcref()
|
||||||
CheckDefAndScriptFailure(['funcref("reverse", 2)'], ['E1013: Argument 2: type mismatch, expected list<any> but got number', 'E1211: List required for argument 2'])
|
CheckDefAndScriptFailure(['funcref("reverse", 2)'], ['E1013: Argument 2: type mismatch, expected list<any> but got number', 'E1211: List required for argument 2'])
|
||||||
CheckDefAndScriptFailure(['funcref("reverse", [2], [1])'], ['E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3'])
|
CheckDefAndScriptFailure(['funcref("reverse", [2], [1])'], ['E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3'])
|
||||||
|
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def UseBool(b: bool)
|
||||||
|
enddef
|
||||||
|
def GetRefOk()
|
||||||
|
var Ref1: func(bool) = funcref(UseBool)
|
||||||
|
var Ref2: func(bool) = funcref('UseBool')
|
||||||
|
enddef
|
||||||
|
def GetRefBad()
|
||||||
|
# only fails at runtime
|
||||||
|
var Ref1: func(number) = funcref(UseBool)
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
GetRefOk()
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def UseBool(b: bool)
|
||||||
|
enddef
|
||||||
|
def GetRefBad()
|
||||||
|
# only fails at runtime
|
||||||
|
var Ref1: func(number) = funcref(UseBool)
|
||||||
|
enddef
|
||||||
|
GetRefBad()
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1012: Type mismatch; expected func(number) but got func(bool)')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_function()
|
def Test_function()
|
||||||
CheckDefAndScriptFailure(['function("reverse", 2)'], ['E1013: Argument 2: type mismatch, expected list<any> but got number', 'E1211: List required for argument 2'])
|
CheckDefAndScriptFailure(['function("reverse", 2)'], ['E1013: Argument 2: type mismatch, expected list<any> but got number', 'E1211: List required for argument 2'])
|
||||||
CheckDefAndScriptFailure(['function("reverse", [2], [1])'], ['E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3'])
|
CheckDefAndScriptFailure(['function("reverse", [2], [1])'], ['E1013: Argument 3: type mismatch, expected dict<any> but got list<number>', 'E1206: Dictionary required for argument 3'])
|
||||||
|
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def UseBool(b: bool)
|
||||||
|
enddef
|
||||||
|
def GetRefOk()
|
||||||
|
var Ref1: func(bool) = function(UseBool)
|
||||||
|
var Ref2: func(bool) = function('UseBool')
|
||||||
|
enddef
|
||||||
|
def GetRefBad()
|
||||||
|
# only fails at runtime
|
||||||
|
var Ref1: func(number) = function(UseBool)
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
GetRefOk()
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
def UseBool(b: bool)
|
||||||
|
enddef
|
||||||
|
def GetRefBad()
|
||||||
|
# only fails at runtime
|
||||||
|
var Ref1: func(number) = function(UseBool)
|
||||||
|
enddef
|
||||||
|
GetRefBad()
|
||||||
|
END
|
||||||
|
CheckScriptFailure(lines, 'E1012: Type mismatch; expected func(number) but got func(bool)')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_garbagecollect()
|
def Test_garbagecollect()
|
||||||
|
@@ -749,6 +749,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
3857,
|
||||||
/**/
|
/**/
|
||||||
3856,
|
3856,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user