patch 9.0.2057: Vim9: no strict type checks for funcrefs varargs
Problem: Vim9: no strict type checks for funcrefs varargs
Solution: Perform strict type checking when declaring funcrefs
with vararg declaration, add tests
closes: #13397
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Ernie Rael <errael@raelity.com>
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index bff9c9f..6d2858f 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -1890,7 +1890,7 @@
var FuncAnyVA: func(...any): number
FuncAnyVA = (v): number => v
END
- v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected func(...any): number but got func(any): number')
+ v9.CheckScriptFailure(lines, 'E1180: Variable arguments type must be a list: any')
# varargs must match
lines =<< trim END
@@ -1898,7 +1898,7 @@
var FuncAnyVA: func(...any): number
FuncAnyVA = (v1, v2): number => v1 + v2
END
- v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected func(...any): number but got func(any, any): number')
+ v9.CheckScriptFailure(lines, 'E1180: Variable arguments type must be a list: any')
# varargs must match
lines =<< trim END
@@ -1906,7 +1906,7 @@
var FuncAnyVA: func(...any): number
FuncAnyVA = (v1: list<any>): number => 3
END
- v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected func(...any): number but got func(list<any>): number')
+ v9.CheckScriptFailure(lines, 'E1180: Variable arguments type must be a list: any')
enddef
def Test_assign_funcref_arg_any()
diff --git a/src/testdir/test_vim9_func.vim b/src/testdir/test_vim9_func.vim
index 701a2f0..cbbd572 100644
--- a/src/testdir/test_vim9_func.vim
+++ b/src/testdir/test_vim9_func.vim
Binary files differ
diff --git a/src/version.c b/src/version.c
index 7584e45..fbf2999 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 2057,
+/**/
2056,
/**/
2055,
diff --git a/src/vim9type.c b/src/vim9type.c
index 6a58487..c31e51b 100644
--- a/src/vim9type.c
+++ b/src/vim9type.c
@@ -1231,6 +1231,15 @@
type = parse_type(&p, type_gap, give_error);
if (type == NULL)
return NULL;
+ if ((flags & TTFLAG_VARARGS) != 0
+ && type->tt_type != VAR_LIST)
+ {
+ char *tofree;
+ semsg(_(e_variable_arguments_type_must_be_list_str),
+ type_name(type, &tofree));
+ vim_free(tofree);
+ return NULL;
+ }
arg_type[argcount++] = type;
// Nothing comes after "...{type}".