mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 9.0.0778: indexing of unknown const type fails during compilation
Problem: Indexing of unknown const type fails during compilation. Solution: Check for "any" properly. (closes #11389)
This commit is contained in:
@@ -3132,6 +3132,30 @@ def Test_expr9_any_index_slice()
|
|||||||
unlet g:testlist
|
unlet g:testlist
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
|
def Test_expr9_const_any_index_slice()
|
||||||
|
var lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
export def V(): dict<any>
|
||||||
|
return {a: [1, 43], b: 0}
|
||||||
|
enddef
|
||||||
|
END
|
||||||
|
writefile(lines, 'XexportDict.vim', 'D')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
vim9script
|
||||||
|
|
||||||
|
import './XexportDict.vim' as x
|
||||||
|
|
||||||
|
def Test()
|
||||||
|
const v = x.V()
|
||||||
|
assert_equal(43, v.a[1])
|
||||||
|
enddef
|
||||||
|
Test()
|
||||||
|
END
|
||||||
|
v9.CheckScriptSuccess(lines)
|
||||||
|
enddef
|
||||||
|
|
||||||
def Test_expr_member_vim9script()
|
def Test_expr_member_vim9script()
|
||||||
var lines =<< trim END
|
var lines =<< trim END
|
||||||
var d = {one:
|
var d = {one:
|
||||||
|
@@ -695,6 +695,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 */
|
||||||
|
/**/
|
||||||
|
778,
|
||||||
/**/
|
/**/
|
||||||
777,
|
777,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -93,7 +93,8 @@ compile_member(int is_slice, int *keeping_dict, cctx_T *cctx)
|
|||||||
vartype = typep->type_curr->tt_type;
|
vartype = typep->type_curr->tt_type;
|
||||||
idxtype = (((type2_T *)stack->ga_data) + stack->ga_len - 1)->type_curr;
|
idxtype = (((type2_T *)stack->ga_data) + stack->ga_len - 1)->type_curr;
|
||||||
// If the index is a string, the variable must be a Dict.
|
// If the index is a string, the variable must be a Dict.
|
||||||
if ((typep->type_curr == &t_any || typep->type_curr == &t_unknown)
|
if ((typep->type_curr->tt_type == VAR_ANY
|
||||||
|
|| typep->type_curr->tt_type == VAR_UNKNOWN)
|
||||||
&& idxtype == &t_string)
|
&& idxtype == &t_string)
|
||||||
vartype = VAR_DICT;
|
vartype = VAR_DICT;
|
||||||
if (vartype == VAR_STRING || vartype == VAR_LIST || vartype == VAR_BLOB)
|
if (vartype == VAR_STRING || vartype == VAR_LIST || vartype == VAR_BLOB)
|
||||||
@@ -172,8 +173,8 @@ compile_member(int is_slice, int *keeping_dict, cctx_T *cctx)
|
|||||||
return FAIL;
|
return FAIL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (vartype == VAR_LIST || typep->type_curr == &t_any
|
else if (vartype == VAR_LIST || typep->type_curr->tt_type == VAR_ANY
|
||||||
|| typep->type_curr == &t_unknown)
|
|| typep->type_curr->tt_type == VAR_UNKNOWN)
|
||||||
{
|
{
|
||||||
if (is_slice)
|
if (is_slice)
|
||||||
{
|
{
|
||||||
@@ -669,7 +670,7 @@ compile_arguments(
|
|||||||
// {sub} argument of substitute() can be compiled if it starts
|
// {sub} argument of substitute() can be compiled if it starts
|
||||||
// with \=
|
// with \=
|
||||||
if (isn->isn_type == ISN_PUSHS && isn->isn_arg.string[0] == '\\'
|
if (isn->isn_type == ISN_PUSHS && isn->isn_arg.string[0] == '\\'
|
||||||
&& isn->isn_arg.string[1] == '=')
|
&& isn->isn_arg.string[1] == '=')
|
||||||
compile_string(isn, cctx, 2);
|
compile_string(isn, cctx, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1646,10 +1647,11 @@ bool_on_stack(cctx_T *cctx)
|
|||||||
if (type == &t_bool)
|
if (type == &t_bool)
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
if (type == &t_any
|
if (type->tt_type == VAR_ANY
|
||||||
|| type == &t_unknown
|
|| type->tt_type == VAR_UNKNOWN
|
||||||
|| type == &t_number
|
|| type->tt_type == VAR_NUMBER
|
||||||
|| type == &t_number_bool)
|
|| type == &t_number_bool
|
||||||
|
|| type == &t_const_number_bool)
|
||||||
// Number 0 and 1 are OK to use as a bool. "any" could also be a bool.
|
// Number 0 and 1 are OK to use as a bool. "any" could also be a bool.
|
||||||
// This requires a runtime type check.
|
// This requires a runtime type check.
|
||||||
return generate_COND2BOOL(cctx);
|
return generate_COND2BOOL(cctx);
|
||||||
|
Reference in New Issue
Block a user