1
0
forked from aniani/vim

patch 8.2.4590: Vim9: range type check has wrong offset

Problem:    Vim9: range type check has wrong offset.
Solution:   Adjust offset for CHECKTYPE.  Remove other type check.
This commit is contained in:
Bram Moolenaar
2022-03-18 21:41:47 +00:00
parent 2e17fef225
commit 2995e5cf4e
4 changed files with 39 additions and 62 deletions

View File

@@ -1602,7 +1602,7 @@ def Test_assign_list()
l[g:idx : 1] = [0] l[g:idx : 1] = [0]
echo l echo l
END END
v9.CheckDefExecAndScriptFailure(lines, 'E1030: Using a String as a Number: "x"') v9.CheckDefExecAndScriptFailure(lines, ['E1012: Type mismatch; expected number but got string', 'E1030: Using a String as a Number: "x"'])
lines =<< trim END lines =<< trim END
var l = [1, 2] var l = [1, 2]

View File

@@ -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 */
/**/
4590,
/**/ /**/
4589, 4589,
/**/ /**/

View File

@@ -1802,7 +1802,7 @@ compile_assign_unlet(
{ {
type = get_type_on_stack(cctx, 1); type = get_type_on_stack(cctx, 1);
if (need_type(type, &t_number, if (need_type(type, &t_number,
-1, 0, cctx, FALSE, FALSE) == FAIL) -2, 0, cctx, FALSE, FALSE) == FAIL)
return FAIL; return FAIL;
} }
type = get_type_on_stack(cctx, 0); type = get_type_on_stack(cctx, 0);

View File

@@ -1896,79 +1896,54 @@ execute_storerange(isn_T *iptr, ectx_T *ectx)
SOURCING_LNUM = iptr->isn_lnum; SOURCING_LNUM = iptr->isn_lnum;
if (tv_dest->v_type == VAR_LIST) if (tv_dest->v_type == VAR_LIST)
{ {
long n1; long n1;
long n2; long n2;
int error = FALSE; listitem_T *li1;
n1 = (long)tv_get_number_chk(tv_idx1, &error); n1 = (long)tv_get_number_chk(tv_idx1, NULL);
if (error) if (tv_idx2->v_type == VAR_SPECIAL
&& tv_idx2->vval.v_number == VVAL_NONE)
n2 = list_len(tv_dest->vval.v_list) - 1;
else
n2 = (long)tv_get_number_chk(tv_idx2, NULL);
li1 = check_range_index_one(tv_dest->vval.v_list, &n1, FALSE);
if (li1 == NULL)
status = FAIL; status = FAIL;
else else
{ {
if (tv_idx2->v_type == VAR_SPECIAL status = check_range_index_two(tv_dest->vval.v_list,
&& tv_idx2->vval.v_number == VVAL_NONE) &n1, li1, &n2, FALSE);
n2 = list_len(tv_dest->vval.v_list) - 1; if (status != FAIL)
else status = list_assign_range(
n2 = (long)tv_get_number_chk(tv_idx2, &error); tv_dest->vval.v_list,
if (error) tv->vval.v_list,
status = FAIL; // cannot happen? n1,
else n2,
{ tv_idx2->v_type == VAR_SPECIAL,
listitem_T *li1 = check_range_index_one( (char_u *)"=",
tv_dest->vval.v_list, &n1, FALSE); (char_u *)"[unknown]");
if (li1 == NULL)
status = FAIL;
else
{
status = check_range_index_two(
tv_dest->vval.v_list,
&n1, li1, &n2, FALSE);
if (status != FAIL)
status = list_assign_range(
tv_dest->vval.v_list,
tv->vval.v_list,
n1,
n2,
tv_idx2->v_type == VAR_SPECIAL,
(char_u *)"=",
(char_u *)"[unknown]");
}
}
} }
} }
else if (tv_dest->v_type == VAR_BLOB) else if (tv_dest->v_type == VAR_BLOB)
{ {
varnumber_T n1; varnumber_T n1;
varnumber_T n2; varnumber_T n2;
int error = FALSE; long bloblen;
n1 = tv_get_number_chk(tv_idx1, &error); n1 = tv_get_number_chk(tv_idx1, NULL);
if (error) if (tv_idx2->v_type == VAR_SPECIAL
&& tv_idx2->vval.v_number == VVAL_NONE)
n2 = blob_len(tv_dest->vval.v_blob) - 1;
else
n2 = tv_get_number_chk(tv_idx2, NULL);
bloblen = blob_len(tv_dest->vval.v_blob);
if (check_blob_index(bloblen, n1, FALSE) == FAIL
|| check_blob_range(bloblen, n1, n2, FALSE) == FAIL)
status = FAIL; status = FAIL;
else else
{ status = blob_set_range(tv_dest->vval.v_blob, n1, n2, tv);
if (tv_idx2->v_type == VAR_SPECIAL
&& tv_idx2->vval.v_number == VVAL_NONE)
n2 = blob_len(tv_dest->vval.v_blob) - 1;
else
n2 = tv_get_number_chk(tv_idx2, &error);
if (error)
status = FAIL;
else
{
long bloblen = blob_len(tv_dest->vval.v_blob);
if (check_blob_index(bloblen,
n1, FALSE) == FAIL
|| check_blob_range(bloblen,
n1, n2, FALSE) == FAIL)
status = FAIL;
else
status = blob_set_range(
tv_dest->vval.v_blob, n1, n2, tv);
}
}
} }
else else
{ {