1
0
forked from aniani/vim

patch 8.2.2323: Vim9: error when inferring type from empty dict/list

Problem:    Vim9: error when inferring type from empty dict/list.
Solution:   When the member is t_unknown use t_any. (closes #7009)
This commit is contained in:
Bram Moolenaar
2021-01-10 19:23:27 +01:00
parent 0186e58639
commit 31a11b942a
3 changed files with 35 additions and 1 deletions

View File

@@ -1899,7 +1899,10 @@ generate_STRINGMEMBER(cctx_T *cctx, char_u *name, size_t len)
}
// change dict type to dict member type
if (type->tt_type == VAR_DICT)
((type_T **)stack->ga_data)[stack->ga_len - 1] = type->tt_member;
{
((type_T **)stack->ga_data)[stack->ga_len - 1] =
type->tt_member == &t_unknown ? &t_any : type->tt_member;
}
return OK;
}
@@ -3793,7 +3796,12 @@ compile_subscript(
return FAIL;
}
if ((*typep)->tt_type == VAR_DICT)
{
*typep = (*typep)->tt_member;
if (*typep == &t_unknown)
// empty dict was used
*typep = &t_any;
}
else
{
if (need_type(*typep, &t_dict_any, -2, cctx,
@@ -3831,7 +3839,12 @@ compile_subscript(
else
{
if ((*typep)->tt_type == VAR_LIST)
{
*typep = (*typep)->tt_member;
if (*typep == &t_unknown)
// empty list was used
*typep = &t_any;
}
if (generate_instr_drop(cctx,
vtype == VAR_LIST ? ISN_LISTINDEX : ISN_ANYINDEX,
1) == FAIL)