0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

patch 8.2.3168: Vim9: type error for constant of type any

Problem:    Vim9: type error for constant of type any.
Solution:   Do add a runtime type check if a constant has type any.
            (closes #8570)
This commit is contained in:
Bram Moolenaar 2021-07-15 19:23:18 +02:00
parent 547f94f330
commit 378697ac58
3 changed files with 14 additions and 1 deletions

View File

@ -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}

View File

@ -755,6 +755,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
3168,
/**/
3167,
/**/

View File

@ -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;