Mercurial > vim
comparison src/vim9execute.c @ 27764:1662d2d2e27b v8.2.4408
patch 8.2.4408: Vim9: some code not covered by tests
Commit: https://github.com/vim/vim/commit/ea5c898b5fb60828b0223f258910f84f5c645e63
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 17 14:42:02 2022 +0000
patch 8.2.4408: Vim9: some code not covered by tests
Problem: Vim9: some code not covered by tests.
Solution: Add a few more tests. Correct error message. Allow unlet on dict
with a number key.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 17 Feb 2022 15:45:03 +0100 |
parents | 3196066c5795 |
children | 2a394907825d |
comparison
equal
deleted
inserted
replaced
27763:87459cbe6138 | 27764:1662d2d2e27b |
---|---|
1874 } | 1874 } |
1875 return OK; | 1875 return OK; |
1876 } | 1876 } |
1877 | 1877 |
1878 /* | 1878 /* |
1879 * Store a value in a blob range. | 1879 * Store a value in a list or blob range. |
1880 */ | 1880 */ |
1881 static int | 1881 static int |
1882 execute_storerange(isn_T *iptr, ectx_T *ectx) | 1882 execute_storerange(isn_T *iptr, ectx_T *ectx) |
1883 { | 1883 { |
1884 typval_T *tv; | 1884 typval_T *tv; |
1891 // -4 value to be stored | 1891 // -4 value to be stored |
1892 // -3 first index or "none" | 1892 // -3 first index or "none" |
1893 // -2 second index or "none" | 1893 // -2 second index or "none" |
1894 // -1 destination list or blob | 1894 // -1 destination list or blob |
1895 tv = STACK_TV_BOT(-4); | 1895 tv = STACK_TV_BOT(-4); |
1896 SOURCING_LNUM = iptr->isn_lnum; | |
1896 if (tv_dest->v_type == VAR_LIST) | 1897 if (tv_dest->v_type == VAR_LIST) |
1897 { | 1898 { |
1898 long n1; | 1899 long n1; |
1899 long n2; | 1900 long n2; |
1900 int error = FALSE; | 1901 int error = FALSE; |
1901 | 1902 |
1902 SOURCING_LNUM = iptr->isn_lnum; | |
1903 n1 = (long)tv_get_number_chk(tv_idx1, &error); | 1903 n1 = (long)tv_get_number_chk(tv_idx1, &error); |
1904 if (error) | 1904 if (error) |
1905 status = FAIL; | 1905 status = FAIL; |
1906 else | 1906 else |
1907 { | 1907 { |
1971 } | 1971 } |
1972 } | 1972 } |
1973 else | 1973 else |
1974 { | 1974 { |
1975 status = FAIL; | 1975 status = FAIL; |
1976 emsg(_(e_blob_required)); | 1976 emsg(_(e_list_or_blob_required)); |
1977 } | 1977 } |
1978 | 1978 |
1979 clear_tv(tv_idx1); | 1979 clear_tv(tv_idx1); |
1980 clear_tv(tv_idx2); | 1980 clear_tv(tv_idx2); |
1981 clear_tv(tv_dest); | 1981 clear_tv(tv_dest); |
1999 // -2 index | 1999 // -2 index |
2000 // -1 dict or list | 2000 // -1 dict or list |
2001 if (tv_dest->v_type == VAR_DICT) | 2001 if (tv_dest->v_type == VAR_DICT) |
2002 { | 2002 { |
2003 // unlet a dict item, index must be a string | 2003 // unlet a dict item, index must be a string |
2004 if (tv_idx->v_type != VAR_STRING) | 2004 if (tv_idx->v_type != VAR_STRING && tv_idx->v_type != VAR_NUMBER) |
2005 { | 2005 { |
2006 SOURCING_LNUM = iptr->isn_lnum; | 2006 SOURCING_LNUM = iptr->isn_lnum; |
2007 semsg(_(e_expected_str_but_got_str), | 2007 semsg(_(e_expected_str_but_got_str), |
2008 vartype_name(VAR_STRING), | 2008 vartype_name(VAR_STRING), |
2009 vartype_name(tv_idx->v_type)); | 2009 vartype_name(tv_idx->v_type)); |
2010 status = FAIL; | 2010 status = FAIL; |
2011 } | 2011 } |
2012 else | 2012 else |
2013 { | 2013 { |
2014 dict_T *d = tv_dest->vval.v_dict; | 2014 dict_T *d = tv_dest->vval.v_dict; |
2015 char_u *key = tv_idx->vval.v_string; | 2015 char_u *key; |
2016 dictitem_T *di = NULL; | 2016 dictitem_T *di = NULL; |
2017 | 2017 |
2018 if (d != NULL && value_check_lock( | 2018 if (d != NULL && value_check_lock( |
2019 d->dv_lock, NULL, FALSE)) | 2019 d->dv_lock, NULL, FALSE)) |
2020 status = FAIL; | 2020 status = FAIL; |
2021 else | 2021 else |
2022 { | 2022 { |
2023 SOURCING_LNUM = iptr->isn_lnum; | 2023 SOURCING_LNUM = iptr->isn_lnum; |
2024 if (key == NULL) | 2024 if (tv_idx->v_type == VAR_STRING) |
2025 key = (char_u *)""; | 2025 { |
2026 key = tv_idx->vval.v_string; | |
2027 if (key == NULL) | |
2028 key = (char_u *)""; | |
2029 } | |
2030 else | |
2031 { | |
2032 key = tv_get_string(tv_idx); | |
2033 } | |
2026 if (d != NULL) | 2034 if (d != NULL) |
2027 di = dict_find(d, key, (int)STRLEN(key)); | 2035 di = dict_find(d, key, (int)STRLEN(key)); |
2028 if (di == NULL) | 2036 if (di == NULL) |
2029 { | 2037 { |
2030 // NULL dict is equivalent to empty dict | 2038 // NULL dict is equivalent to empty dict |
3171 if (res == NOTDONE) | 3179 if (res == NOTDONE) |
3172 goto theend; | 3180 goto theend; |
3173 } | 3181 } |
3174 break; | 3182 break; |
3175 | 3183 |
3176 // store value in blob range | 3184 // store value in list or blob range |
3177 case ISN_STORERANGE: | 3185 case ISN_STORERANGE: |
3178 if (execute_storerange(iptr, ectx) == FAIL) | 3186 if (execute_storerange(iptr, ectx) == FAIL) |
3179 goto on_error; | 3187 goto on_error; |
3180 break; | 3188 break; |
3181 | 3189 |