forked from aniani/vim
patch 8.2.3717: Vim9: error for constant list size is only given at runtime
Problem: Vim9: error for constant list size is only given at runtime. Solution: Give the error at compile time if possible.
This commit is contained in:
parent
e4eed8c6db
commit
db9ff9ab5d
@ -383,6 +383,27 @@ def Test_assign_unpack()
|
|||||||
END
|
END
|
||||||
CheckDefAndScriptSuccess(lines)
|
CheckDefAndScriptSuccess(lines)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var v1: number
|
||||||
|
var v2: number
|
||||||
|
[v1, v2] = [1, 2, 3]
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1093: Expected 2 items but got 3', 3)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var v1: number
|
||||||
|
var v2: number
|
||||||
|
[v1, v2] = [1]
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1093: Expected 2 items but got 1', 3)
|
||||||
|
|
||||||
|
lines =<< trim END
|
||||||
|
var v1: number
|
||||||
|
var v2: number
|
||||||
|
[v1, v2; _] = [1]
|
||||||
|
END
|
||||||
|
CheckDefFailure(lines, 'E1093: Expected 2 items but got 1', 3)
|
||||||
|
|
||||||
lines =<< trim END
|
lines =<< trim END
|
||||||
var v1: number
|
var v1: number
|
||||||
var v2: number
|
var v2: number
|
||||||
|
@ -471,7 +471,6 @@ def Test_disassemble_list_assign_with_op()
|
|||||||
'\d\+ PUSHNR 4\_s*' ..
|
'\d\+ PUSHNR 4\_s*' ..
|
||||||
'\d\+ PUSHNR 5\_s*' ..
|
'\d\+ PUSHNR 5\_s*' ..
|
||||||
'\d\+ NEWLIST size 2\_s*' ..
|
'\d\+ NEWLIST size 2\_s*' ..
|
||||||
'\d\+ CHECKLEN 2\_s*' ..
|
|
||||||
'\d\+ LOAD $0\_s*' ..
|
'\d\+ LOAD $0\_s*' ..
|
||||||
'\d\+ ITEM 0 with op\_s*' ..
|
'\d\+ ITEM 0 with op\_s*' ..
|
||||||
'\d\+ OPNR +\_s*' ..
|
'\d\+ OPNR +\_s*' ..
|
||||||
|
@ -496,8 +496,9 @@ def Test_try_catch_throw()
|
|||||||
endtry
|
endtry
|
||||||
assert_equal(266, n)
|
assert_equal(266, n)
|
||||||
|
|
||||||
|
l = [1, 2, 3]
|
||||||
try
|
try
|
||||||
[n] = [1, 2, 3]
|
[n] = l
|
||||||
catch /E1093:/
|
catch /E1093:/
|
||||||
n = 277
|
n = 277
|
||||||
endtry
|
endtry
|
||||||
@ -4327,7 +4328,8 @@ def Test_catch_exception_in_callback()
|
|||||||
var x: string
|
var x: string
|
||||||
var y: string
|
var y: string
|
||||||
# this error should be caught with CHECKLEN
|
# this error should be caught with CHECKLEN
|
||||||
[x, y] = ['']
|
var sl = ['']
|
||||||
|
[x, y] = sl
|
||||||
catch
|
catch
|
||||||
g:caught = 'yes'
|
g:caught = 'yes'
|
||||||
endtry
|
endtry
|
||||||
|
@ -753,6 +753,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 */
|
||||||
|
/**/
|
||||||
|
3717,
|
||||||
/**/
|
/**/
|
||||||
3716,
|
3716,
|
||||||
/**/
|
/**/
|
||||||
|
@ -6999,6 +6999,8 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
if (cctx->ctx_skip != SKIP_YES)
|
if (cctx->ctx_skip != SKIP_YES)
|
||||||
{
|
{
|
||||||
type_T *stacktype;
|
type_T *stacktype;
|
||||||
|
int needed_list_len;
|
||||||
|
int did_check = FALSE;
|
||||||
|
|
||||||
stacktype = stack->ga_len == 0 ? &t_void
|
stacktype = stack->ga_len == 0 ? &t_void
|
||||||
: ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
: ((type_T **)stack->ga_data)[stack->ga_len - 1];
|
||||||
@ -7010,9 +7012,26 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx)
|
|||||||
if (need_type(stacktype, &t_list_any, -1, 0, cctx,
|
if (need_type(stacktype, &t_list_any, -1, 0, cctx,
|
||||||
FALSE, FALSE) == FAIL)
|
FALSE, FALSE) == FAIL)
|
||||||
goto theend;
|
goto theend;
|
||||||
// TODO: check the length of a constant list here
|
// If a constant list was used we can check the length right here.
|
||||||
generate_CHECKLEN(cctx, semicolon ? var_count - 1 : var_count,
|
needed_list_len = semicolon ? var_count - 1 : var_count;
|
||||||
semicolon);
|
if (instr->ga_len > 0)
|
||||||
|
{
|
||||||
|
isn_T *isn = ((isn_T *)instr->ga_data) + instr->ga_len - 1;
|
||||||
|
|
||||||
|
if (isn->isn_type == ISN_NEWLIST)
|
||||||
|
{
|
||||||
|
did_check = TRUE;
|
||||||
|
if (semicolon ? isn->isn_arg.number < needed_list_len
|
||||||
|
: isn->isn_arg.number != needed_list_len)
|
||||||
|
{
|
||||||
|
semsg(_(e_expected_nr_items_but_got_nr),
|
||||||
|
needed_list_len, isn->isn_arg.number);
|
||||||
|
goto theend;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!did_check)
|
||||||
|
generate_CHECKLEN(cctx, needed_list_len, semicolon);
|
||||||
if (stacktype->tt_member != NULL)
|
if (stacktype->tt_member != NULL)
|
||||||
rhs_type = stacktype->tt_member;
|
rhs_type = stacktype->tt_member;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user