mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
patch 8.2.4285: Vim9: type of item in for loop not checked properly
Problem: Vim9: type of item in for loop not checked properly. Solution: Adjust the type checking. (closes #9683)
This commit is contained in:
@@ -4,6 +4,7 @@ int arg_exists(char_u *name, size_t len, int *idxp, type_T **type, int *gen_load
|
|||||||
int script_is_vim9(void);
|
int script_is_vim9(void);
|
||||||
int script_var_exists(char_u *name, size_t len, cctx_T *cctx);
|
int script_var_exists(char_u *name, size_t len, cctx_T *cctx);
|
||||||
int check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg);
|
int check_defined(char_u *p, size_t len, cctx_T *cctx, int is_arg);
|
||||||
|
int need_type_where(type_T *actual, type_T *expected, int offset, where_T where, cctx_T *cctx, int silent, int actual_is_const);
|
||||||
int need_type(type_T *actual, type_T *expected, int offset, int arg_idx, cctx_T *cctx, int silent, int actual_is_const);
|
int need_type(type_T *actual, type_T *expected, int offset, int arg_idx, cctx_T *cctx, int silent, int actual_is_const);
|
||||||
lvar_T *reserve_local(cctx_T *cctx, char_u *name, size_t len, int isConst, type_T *type);
|
lvar_T *reserve_local(cctx_T *cctx, char_u *name, size_t len, int isConst, type_T *type);
|
||||||
int get_script_item_idx(int sid, char_u *name, int check_writable, cctx_T *cctx);
|
int get_script_item_idx(int sid, char_u *name, int check_writable, cctx_T *cctx);
|
||||||
|
@@ -2011,7 +2011,7 @@ def Test_for_loop_fails()
|
|||||||
echo k v
|
echo k v
|
||||||
endfor
|
endfor
|
||||||
END
|
END
|
||||||
v9.CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected job but got string', 2)
|
v9.CheckDefExecAndScriptFailure(lines, ['E1013: Argument 1: type mismatch, expected job but got string', 'E1012: Type mismatch; expected job but got string'], 2)
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
var i = 0
|
var i = 0
|
||||||
@@ -2036,6 +2036,22 @@ def Test_for_loop_fails()
|
|||||||
endfor
|
endfor
|
||||||
END
|
END
|
||||||
v9.CheckDefExecAndScriptFailure(lines, ['E461:', 'E1017:'])
|
v9.CheckDefExecAndScriptFailure(lines, ['E461:', 'E1017:'])
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var l: list<dict<any>> = [{a: 1, b: 'x'}]
|
||||||
|
for item: dict<number> in l
|
||||||
|
echo item
|
||||||
|
endfor
|
||||||
|
END
|
||||||
|
v9.CheckDefExecAndScriptFailure(lines, 'E1012: Type mismatch; expected dict<number> but got dict<any>')
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var l: list<dict<any>> = [{n: 1}]
|
||||||
|
for item: dict<number> in l
|
||||||
|
item->extend({s: ''})
|
||||||
|
endfor
|
||||||
|
END
|
||||||
|
v9.CheckDefExecAndScriptFailure(lines, 'E1013: Argument 2: type mismatch, expected dict<number> but got dict<string>')
|
||||||
enddef
|
enddef
|
||||||
|
|
||||||
def Test_for_loop_script_var()
|
def Test_for_loop_script_var()
|
||||||
|
@@ -746,6 +746,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 */
|
||||||
|
/**/
|
||||||
|
4285,
|
||||||
/**/
|
/**/
|
||||||
4284,
|
4284,
|
||||||
/**/
|
/**/
|
||||||
|
@@ -990,11 +990,8 @@ compile_for(char_u *arg_start, cctx_T *cctx)
|
|||||||
if (lhs_type == &t_any)
|
if (lhs_type == &t_any)
|
||||||
lhs_type = item_type;
|
lhs_type = item_type;
|
||||||
else if (item_type != &t_unknown
|
else if (item_type != &t_unknown
|
||||||
&& (item_type == &t_any
|
&& need_type_where(item_type, lhs_type, -1,
|
||||||
? need_type(item_type, lhs_type,
|
where, cctx, FALSE, FALSE) == FAIL)
|
||||||
-1, 0, cctx, FALSE, FALSE)
|
|
||||||
: check_type(lhs_type, item_type, TRUE, where))
|
|
||||||
== FAIL)
|
|
||||||
goto failed;
|
goto failed;
|
||||||
var_lvar = reserve_local(cctx, arg, varlen, TRUE, lhs_type);
|
var_lvar = reserve_local(cctx, arg, varlen, TRUE, lhs_type);
|
||||||
if (var_lvar == NULL)
|
if (var_lvar == NULL)
|
||||||
@@ -1003,8 +1000,6 @@ compile_for(char_u *arg_start, cctx_T *cctx)
|
|||||||
|
|
||||||
if (semicolon && idx == var_count - 1)
|
if (semicolon && idx == var_count - 1)
|
||||||
var_lvar->lv_type = vartype;
|
var_lvar->lv_type = vartype;
|
||||||
else
|
|
||||||
var_lvar->lv_type = item_type;
|
|
||||||
generate_STORE(cctx, ISN_STORE, var_lvar->lv_idx, NULL);
|
generate_STORE(cctx, ISN_STORE, var_lvar->lv_idx, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -386,7 +386,7 @@ use_typecheck(type_T *actual, type_T *expected)
|
|||||||
* If "actual_is_const" is TRUE then the type won't change at runtime, do not
|
* If "actual_is_const" is TRUE then the type won't change at runtime, do not
|
||||||
* generate a TYPECHECK.
|
* generate a TYPECHECK.
|
||||||
*/
|
*/
|
||||||
static int
|
int
|
||||||
need_type_where(
|
need_type_where(
|
||||||
type_T *actual,
|
type_T *actual,
|
||||||
type_T *expected,
|
type_T *expected,
|
||||||
|
Reference in New Issue
Block a user