# HG changeset patch # User Bram Moolenaar # Date 1647639902 -3600 # Node ID d8bf200cd761aba5cc6ef9ac16b8a4daec4556fe # Parent f7483c7afd6cf27ab3a23c480bbf1236b2301832 patch 8.2.4590: Vim9: range type check has wrong offset Commit: https://github.com/vim/vim/commit/2995e5cf4eb9651827788e14f9f42ab34ce4c7e1 Author: Bram Moolenaar Date: Fri Mar 18 21:41:47 2022 +0000 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. diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim --- a/src/testdir/test_vim9_assign.vim +++ b/src/testdir/test_vim9_assign.vim @@ -1602,7 +1602,7 @@ def Test_assign_list() l[g:idx : 1] = [0] echo l 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 var l = [1, 2] diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4590, +/**/ 4589, /**/ 4588, diff --git a/src/vim9compile.c b/src/vim9compile.c --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1802,7 +1802,7 @@ compile_assign_unlet( { type = get_type_on_stack(cctx, 1); if (need_type(type, &t_number, - -1, 0, cctx, FALSE, FALSE) == FAIL) + -2, 0, cctx, FALSE, FALSE) == FAIL) return FAIL; } type = get_type_on_stack(cctx, 0); diff --git a/src/vim9execute.c b/src/vim9execute.c --- a/src/vim9execute.c +++ b/src/vim9execute.c @@ -1896,79 +1896,54 @@ execute_storerange(isn_T *iptr, ectx_T * SOURCING_LNUM = iptr->isn_lnum; if (tv_dest->v_type == VAR_LIST) { - long n1; - long n2; - int error = FALSE; - - n1 = (long)tv_get_number_chk(tv_idx1, &error); - if (error) + long n1; + long n2; + listitem_T *li1; + + n1 = (long)tv_get_number_chk(tv_idx1, NULL); + 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; else { - 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, &error); - if (error) - status = FAIL; // cannot happen? - else - { - listitem_T *li1 = check_range_index_one( - tv_dest->vval.v_list, &n1, FALSE); - - 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]"); - } - } + 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) { varnumber_T n1; varnumber_T n2; - int error = FALSE; - - n1 = tv_get_number_chk(tv_idx1, &error); - if (error) + long bloblen; + + n1 = tv_get_number_chk(tv_idx1, NULL); + 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; else - { - 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); - } - } + status = blob_set_range(tv_dest->vval.v_blob, n1, n2, tv); } else {