diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-07-15 19:23:18 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-07-15 19:23:18 +0200 |
commit | 378697ac58b8f9705286e36d1805a052e96fb86e (patch) | |
tree | 38efb1d1cea655cfaaf4fce39b5c0b943107df63 | |
parent | 547f94f33098b060da9d62c29d9fcbe9bf1e2b11 (diff) | |
download | vim-git-378697ac58b8f9705286e36d1805a052e96fb86e.tar.gz |
patch 8.2.3168: Vim9: type error for constant of type anyv8.2.3168
Problem: Vim9: type error for constant of type any.
Solution: Do add a runtime type check if a constant has type any.
(closes #8570)
-rw-r--r-- | src/testdir/test_vim9_assign.vim | 10 | ||||
-rw-r--r-- | src/version.c | 2 | ||||
-rw-r--r-- | src/vim9compile.c | 3 |
3 files changed, 14 insertions, 1 deletions
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim index 6bbbc3681..3599d6c5d 100644 --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -1667,6 +1667,16 @@ def Test_var_type_check() s:d = {} END CheckScriptSuccess(lines) + + lines =<< trim END + vim9script + var d = {a: 1, b: [2]} + def Func(b: bool) + var l: list<number> = b ? d.b : [3] + enddef + defcompile + END + CheckScriptSuccess(lines) enddef let g:dict_number = #{one: 1, two: 2} diff --git a/src/version.c b/src/version.c index 6a4943d50..b8c782eef 100644 --- a/src/version.c +++ b/src/version.c @@ -756,6 +756,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 3168, +/**/ 3167, /**/ 3166, diff --git a/src/vim9compile.c b/src/vim9compile.c index 4763e9550..956ce44eb 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1051,7 +1051,8 @@ need_type( // 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 && use_typecheck(actual, expected)) + if ((!actual_is_const || actual == &t_any) + && use_typecheck(actual, expected)) { generate_TYPECHECK(cctx, expected, offset, arg_idx); return OK; |