Mercurial > vim
comparison src/vim9execute.c @ 20871:65d9189d4dca v8.2.0987
patch 8.2.0987: Vim9: cannot assign to [var; var]
Commit: https://github.com/vim/vim/commit/9af78769eeae0318e07aa8b6af4d6e2244481ca7
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 16 11:34:42 2020 +0200
patch 8.2.0987: Vim9: cannot assign to [var; var]
Problem: Vim9: cannot assign to [var; var].
Solution: Assign rest of items to a list.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 16 Jun 2020 11:45:04 +0200 |
parents | 876e16c48bd1 |
children | a3853794a768 |
comparison
equal
deleted
inserted
replaced
20870:6203fd2cfb51 | 20871:65d9189d4dca |
---|---|
2112 clear_tv(STACK_TV_BOT(-1)); | 2112 clear_tv(STACK_TV_BOT(-1)); |
2113 copy_tv(&li->li_tv, STACK_TV_BOT(-1)); | 2113 copy_tv(&li->li_tv, STACK_TV_BOT(-1)); |
2114 } | 2114 } |
2115 break; | 2115 break; |
2116 | 2116 |
2117 case ISN_SLICE: | |
2118 { | |
2119 list_T *list; | |
2120 int count = iptr->isn_arg.number; | |
2121 | |
2122 tv = STACK_TV_BOT(-1); | |
2123 if (tv->v_type != VAR_LIST) | |
2124 { | |
2125 emsg(_(e_listreq)); | |
2126 goto failed; | |
2127 } | |
2128 list = tv->vval.v_list; | |
2129 | |
2130 // no error for short list, expect it to be checked earlier | |
2131 if (list != NULL && list->lv_len >= count) | |
2132 { | |
2133 list_T *newlist = list_slice(list, | |
2134 count, list->lv_len - 1); | |
2135 | |
2136 if (newlist != NULL) | |
2137 { | |
2138 list_unref(list); | |
2139 tv->vval.v_list = newlist; | |
2140 ++newlist->lv_refcount; | |
2141 } | |
2142 } | |
2143 } | |
2144 break; | |
2145 | |
2117 case ISN_GETITEM: | 2146 case ISN_GETITEM: |
2118 { | 2147 { |
2119 listitem_T *li; | 2148 listitem_T *li; |
2120 int index = iptr->isn_arg.number; | 2149 int index = iptr->isn_arg.number; |
2121 | 2150 |
2236 && ct->ct_type == VAR_PARTIAL))) | 2265 && ct->ct_type == VAR_PARTIAL))) |
2237 { | 2266 { |
2238 semsg(_("E1029: Expected %s but got %s"), | 2267 semsg(_("E1029: Expected %s but got %s"), |
2239 vartype_name(ct->ct_type), | 2268 vartype_name(ct->ct_type), |
2240 vartype_name(tv->v_type)); | 2269 vartype_name(tv->v_type)); |
2270 goto failed; | |
2271 } | |
2272 } | |
2273 break; | |
2274 | |
2275 case ISN_CHECKLEN: | |
2276 { | |
2277 int min_len = iptr->isn_arg.checklen.cl_min_len; | |
2278 list_T *list = NULL; | |
2279 | |
2280 tv = STACK_TV_BOT(-1); | |
2281 if (tv->v_type == VAR_LIST) | |
2282 list = tv->vval.v_list; | |
2283 if (list == NULL || list->lv_len < min_len | |
2284 || (list->lv_len > min_len | |
2285 && !iptr->isn_arg.checklen.cl_more_OK)) | |
2286 { | |
2287 semsg(_("E1093: Expected %d items but got %d"), | |
2288 min_len, list == NULL ? 0 : list->lv_len); | |
2241 goto failed; | 2289 goto failed; |
2242 } | 2290 } |
2243 } | 2291 } |
2244 break; | 2292 break; |
2245 | 2293 |
2812 case ISN_ADDBLOB: smsg("%4d ADDBLOB", current); break; | 2860 case ISN_ADDBLOB: smsg("%4d ADDBLOB", current); break; |
2813 | 2861 |
2814 // expression operations | 2862 // expression operations |
2815 case ISN_CONCAT: smsg("%4d CONCAT", current); break; | 2863 case ISN_CONCAT: smsg("%4d CONCAT", current); break; |
2816 case ISN_INDEX: smsg("%4d INDEX", current); break; | 2864 case ISN_INDEX: smsg("%4d INDEX", current); break; |
2865 case ISN_SLICE: smsg("%4d SLICE %lld", | |
2866 current, iptr->isn_arg.number); break; | |
2817 case ISN_GETITEM: smsg("%4d ITEM %lld", | 2867 case ISN_GETITEM: smsg("%4d ITEM %lld", |
2818 current, iptr->isn_arg.number); break; | 2868 current, iptr->isn_arg.number); break; |
2819 case ISN_MEMBER: smsg("%4d MEMBER", current); break; | 2869 case ISN_MEMBER: smsg("%4d MEMBER", current); break; |
2820 case ISN_STRINGMEMBER: smsg("%4d MEMBER %s", current, | 2870 case ISN_STRINGMEMBER: smsg("%4d MEMBER %s", current, |
2821 iptr->isn_arg.string); break; | 2871 iptr->isn_arg.string); break; |
2824 case ISN_CHECKNR: smsg("%4d CHECKNR", current); break; | 2874 case ISN_CHECKNR: smsg("%4d CHECKNR", current); break; |
2825 case ISN_CHECKTYPE: smsg("%4d CHECKTYPE %s stack[%d]", current, | 2875 case ISN_CHECKTYPE: smsg("%4d CHECKTYPE %s stack[%d]", current, |
2826 vartype_name(iptr->isn_arg.type.ct_type), | 2876 vartype_name(iptr->isn_arg.type.ct_type), |
2827 iptr->isn_arg.type.ct_off); | 2877 iptr->isn_arg.type.ct_off); |
2828 break; | 2878 break; |
2879 case ISN_CHECKLEN: smsg("%4d CHECKLEN %s%d", current, | |
2880 iptr->isn_arg.checklen.cl_more_OK ? ">= " : "", | |
2881 iptr->isn_arg.checklen.cl_min_len); | |
2882 break; | |
2829 case ISN_2BOOL: if (iptr->isn_arg.number) | 2883 case ISN_2BOOL: if (iptr->isn_arg.number) |
2830 smsg("%4d INVERT (!val)", current); | 2884 smsg("%4d INVERT (!val)", current); |
2831 else | 2885 else |
2832 smsg("%4d 2BOOL (!!val)", current); | 2886 smsg("%4d 2BOOL (!!val)", current); |
2833 break; | 2887 break; |