patch 8.2.0659: Vim9: no test for equal func type
Problem: Vim9: no test for equal func type.
Solution: Add a test. Improve type check.
diff --git a/src/testdir/test_vim9_expr.vim b/src/testdir/test_vim9_expr.vim
index ace3d2f..ef5c00c 100644
--- a/src/testdir/test_vim9_expr.vim
+++ b/src/testdir/test_vim9_expr.vim
@@ -30,6 +30,16 @@
assert_equal('two', {} ? 'one' : 'two')
var = 0
assert_equal('two', var ? 'one' : 'two')
+
+ let Some: func = function('len')
+ let Other: func = function('winnr')
+ let Res: func = g:atrue ? Some : Other
+ assert_equal(function('len'), Res)
+
+ let RetOne: func(string): number = function('len')
+ let RetTwo: func(string): number = function('winnr')
+ let RetThat: func = g:atrue ? RetOne : RetTwo
+ assert_equal(function('len'), RetThat)
enddef
func Test_expr1_fails()
diff --git a/src/version.c b/src/version.c
index 127f906..d3a1b0b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -747,6 +747,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 659,
+/**/
658,
/**/
657,
diff --git a/src/vim9compile.c b/src/vim9compile.c
index aa3cd07..7b433a3 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -724,7 +724,8 @@
RETURN_OK_IF_SKIP(cctx);
if ((isn = generate_instr(cctx, ISN_CHECKTYPE)) == NULL)
return FAIL;
- isn->isn_arg.type.ct_type = vartype->tt_type; // TODO: whole type
+ // TODO: whole type, e.g. for a function also arg and return types
+ isn->isn_arg.type.ct_type = vartype->tt_type;
isn->isn_arg.type.ct_off = offset;
// type becomes vartype
@@ -2594,6 +2595,7 @@
/*
* Check if the expected and actual types match.
+ * Does not allow for assigning "any" to a specific type.
*/
static int
check_type(type_T *expected, type_T *actual, int give_msg)
@@ -2603,7 +2605,8 @@
// When expected is "unknown" we accept any actual type.
// When expected is "any" we accept any actual type except "void".
if (expected->tt_type != VAR_UNKNOWN
- && (expected->tt_type != VAR_ANY || actual->tt_type == VAR_VOID))
+ && !(expected->tt_type == VAR_ANY && actual->tt_type != VAR_VOID))
+
{
if (expected->tt_type != actual->tt_type)
{
@@ -2643,7 +2646,10 @@
{
if (check_type(expected, actual, FALSE) == OK)
return OK;
- if (actual->tt_type != VAR_ANY && actual->tt_type != VAR_UNKNOWN)
+ if (actual->tt_type != VAR_ANY
+ && actual->tt_type != VAR_UNKNOWN
+ && !(actual->tt_type == VAR_FUNC
+ && (actual->tt_member == &t_any || actual->tt_argcount < 0)))
{
type_mismatch(expected, actual);
return FAIL;