Mercurial > vim
diff src/vim9compile.c @ 26680:1b288eb2fcdc v8.2.3869
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Commit: https://github.com/vim/vim/commit/fa46ead31abe66494da775921feefece02ce6d95
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Dec 22 13:18:39 2021 +0000
patch 8.2.3869: Vim9: type checking for "any" is inconsistent
Problem: Vim9: type checking for "any" is inconsistent.
Solution: Always use a runtime type check for using "any" for a more
specific type.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 22 Dec 2021 14:30:05 +0100 |
parents | 4b23672d1f0e |
children | b969fdb8cd46 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -366,8 +366,11 @@ use_typecheck(type_T *actual, type_T *ex || (actual->tt_type == VAR_FUNC && (expected->tt_type == VAR_FUNC || expected->tt_type == VAR_PARTIAL) - && (actual->tt_member == &t_any || actual->tt_argcount < 0) - && ((actual->tt_member == &t_void) + && (actual->tt_member == &t_any + || actual->tt_member == &t_unknown + || actual->tt_argcount < 0) + && (actual->tt_member == &t_unknown || + (actual->tt_member == &t_void) == (expected->tt_member == &t_void)))) return TRUE; if ((actual->tt_type == VAR_LIST || actual->tt_type == VAR_DICT) @@ -412,8 +415,7 @@ need_type_where( // 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 (ret == MAYBE || ((!actual_is_const || actual == &t_any) - && use_typecheck(actual, expected))) + if (!actual_is_const && ret == MAYBE && use_typecheck(actual, expected)) { generate_TYPECHECK(cctx, expected, offset, where.wt_index); return OK; @@ -2547,8 +2549,8 @@ compile_def_function( did_set_arg_type = TRUE; ufunc->uf_arg_types[arg_idx] = val_type; } - else if (check_type(ufunc->uf_arg_types[arg_idx], val_type, - TRUE, where) == FAIL) + else if (need_type_where(val_type, ufunc->uf_arg_types[arg_idx], + -1, where, &cctx, FALSE, FALSE) == FAIL) goto erret; if (generate_STORE(&cctx, ISN_STORE, i - count - off, NULL) == FAIL)