diff src/vim9compile.c @ 26630:57bc1001160b v8.2.3844

patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string) Commit: https://github.com/vim/vim/commit/44a8977de467241a2f9959253d06eff53a8baad9 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Dec 18 12:31:33 2021 +0000 patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string) Problem: Vim9: no type error if assigning a value with type func(number) to a variable of type func(string). Solution: Use check_type_maybe(): return MAYBE if a runtime type check is useful. (issue #8492)
author Bram Moolenaar <Bram@vim.org>
date Sat, 18 Dec 2021 13:45:04 +0100
parents fac6673086df
children 6f8d3470fa90
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -1061,6 +1061,8 @@ need_type_where(
 	int	silent,
 	int	actual_is_const)
 {
+    int ret;
+
     if (expected == &t_bool && actual != &t_bool
 					&& (actual->tt_flags & TTFLAG_BOOL_OK))
     {
@@ -1070,13 +1072,14 @@ need_type_where(
 	return OK;
     }
 
-    if (check_type(expected, actual, FALSE, where) == OK)
+    ret = check_type_maybe(expected, actual, FALSE, where);
+    if (ret == OK)
 	return OK;
 
     // If the actual type can be the expected type add a runtime check.
     // If it's a constant a runtime check makes no sense.
-    if ((!actual_is_const || actual == &t_any)
-					    && use_typecheck(actual, expected))
+    if (ret == MAYBE || ((!actual_is_const || actual == &t_any)
+					   && use_typecheck(actual, expected)))
     {
 	generate_TYPECHECK(cctx, expected, offset, where.wt_index);
 	return OK;