comparison 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
comparison
equal deleted inserted replaced
26629:035ed69c1e5e 26630:57bc1001160b
1059 where_T where, 1059 where_T where,
1060 cctx_T *cctx, 1060 cctx_T *cctx,
1061 int silent, 1061 int silent,
1062 int actual_is_const) 1062 int actual_is_const)
1063 { 1063 {
1064 int ret;
1065
1064 if (expected == &t_bool && actual != &t_bool 1066 if (expected == &t_bool && actual != &t_bool
1065 && (actual->tt_flags & TTFLAG_BOOL_OK)) 1067 && (actual->tt_flags & TTFLAG_BOOL_OK))
1066 { 1068 {
1067 // Using "0", "1" or the result of an expression with "&&" or "||" as a 1069 // Using "0", "1" or the result of an expression with "&&" or "||" as a
1068 // boolean is OK but requires a conversion. 1070 // boolean is OK but requires a conversion.
1069 generate_2BOOL(cctx, FALSE, offset); 1071 generate_2BOOL(cctx, FALSE, offset);
1070 return OK; 1072 return OK;
1071 } 1073 }
1072 1074
1073 if (check_type(expected, actual, FALSE, where) == OK) 1075 ret = check_type_maybe(expected, actual, FALSE, where);
1076 if (ret == OK)
1074 return OK; 1077 return OK;
1075 1078
1076 // If the actual type can be the expected type add a runtime check. 1079 // If the actual type can be the expected type add a runtime check.
1077 // If it's a constant a runtime check makes no sense. 1080 // If it's a constant a runtime check makes no sense.
1078 if ((!actual_is_const || actual == &t_any) 1081 if (ret == MAYBE || ((!actual_is_const || actual == &t_any)
1079 && use_typecheck(actual, expected)) 1082 && use_typecheck(actual, expected)))
1080 { 1083 {
1081 generate_TYPECHECK(cctx, expected, offset, where.wt_index); 1084 generate_TYPECHECK(cctx, expected, offset, where.wt_index);
1082 return OK; 1085 return OK;
1083 } 1086 }
1084 1087