mirror of
https://github.com/vim/vim.git
synced 2025-07-25 10:54:51 -04:00
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:
parent
0186e58639
commit
31a11b942a
@ -2929,6 +2929,16 @@ def Test_expr7_list_subscript()
|
|||||||
lines = ['var l = [0, 1, 2]', 'echo l[g:astring : g:theone]']
|
lines = ['var l = [0, 1, 2]', 'echo l[g:astring : g:theone]']
|
||||||
CheckDefExecFailure(lines, 'E1012:')
|
CheckDefExecFailure(lines, 'E1012:')
|
||||||
CheckScriptFailure(['vim9script'] + lines, 'E1030:', 3)
|
CheckScriptFailure(['vim9script'] + lines, 'E1030:', 3)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
var ld = []
|
||||||
|
def Func()
|
||||||
|
eval ld[0].key
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
|
END
|
||||||
|
CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_expr7_dict_subscript()
|
def Test_expr7_dict_subscript()
|
||||||
@ -2937,6 +2947,15 @@ def Test_expr7_dict_subscript()
|
|||||||
var l = [{lnum: 2}, {lnum: 1}]
|
var l = [{lnum: 2}, {lnum: 1}]
|
||||||
var res = l[0].lnum > l[1].lnum
|
var res = l[0].lnum > l[1].lnum
|
||||||
assert_true(res)
|
assert_true(res)
|
||||||
|
|
||||||
|
var dd = {}
|
||||||
|
def Func1()
|
||||||
|
eval dd.key1.key2
|
||||||
|
enddef
|
||||||
|
def Func2()
|
||||||
|
eval dd['key1'].key2
|
||||||
|
enddef
|
||||||
|
defcompile
|
||||||
END
|
END
|
||||||
CheckScriptSuccess(lines)
|
CheckScriptSuccess(lines)
|
||||||
enddef
|
enddef
|
||||||
|
@ -750,6 +750,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
2323,
|
||||||
/**/
|
/**/
|
||||||
2322,
|
2322,
|
||||||
/**/
|
/**/
|
||||||
|
@ -1899,7 +1899,10 @@ generate_STRINGMEMBER(cctx_T *cctx, char_u *name, size_t len)
|
|||||||
}
|
}
|
||||||
// change dict type to dict member type
|
// change dict type to dict member type
|
||||||
if (type->tt_type == VAR_DICT)
|
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;
|
return OK;
|
||||||
}
|
}
|
||||||
@ -3793,7 +3796,12 @@ compile_subscript(
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
if ((*typep)->tt_type == VAR_DICT)
|
if ((*typep)->tt_type == VAR_DICT)
|
||||||
|
{
|
||||||
*typep = (*typep)->tt_member;
|
*typep = (*typep)->tt_member;
|
||||||
|
if (*typep == &t_unknown)
|
||||||
|
// empty dict was used
|
||||||
|
*typep = &t_any;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (need_type(*typep, &t_dict_any, -2, cctx,
|
if (need_type(*typep, &t_dict_any, -2, cctx,
|
||||||
@ -3831,7 +3839,12 @@ compile_subscript(
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ((*typep)->tt_type == VAR_LIST)
|
if ((*typep)->tt_type == VAR_LIST)
|
||||||
|
{
|
||||||
*typep = (*typep)->tt_member;
|
*typep = (*typep)->tt_member;
|
||||||
|
if (*typep == &t_unknown)
|
||||||
|
// empty list was used
|
||||||
|
*typep = &t_any;
|
||||||
|
}
|
||||||
if (generate_instr_drop(cctx,
|
if (generate_instr_drop(cctx,
|
||||||
vtype == VAR_LIST ? ISN_LISTINDEX : ISN_ANYINDEX,
|
vtype == VAR_LIST ? ISN_LISTINDEX : ISN_ANYINDEX,
|
||||||
1) == FAIL)
|
1) == FAIL)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user