@@ -5865,13 +5865,35 @@ compile_assign_unlet(
58655865 vartype_T dest_type ;
58665866 size_t varlen = lhs -> lhs_varlen ;
58675867 garray_T * stack = & cctx -> ctx_type_stack ;
5868+ int range = FALSE;
58685869
58695870 // Compile the "idx" in "var[idx]" or "key" in "var.key".
58705871 p = var_start + varlen ;
58715872 if (* p == '[' )
58725873 {
58735874 p = skipwhite (p + 1 );
58745875 r = compile_expr0 (& p , cctx );
5876+
5877+ if (r == OK && * skipwhite (p ) == ':' )
5878+ {
5879+ // unlet var[idx : idx]
5880+ if (is_assign )
5881+ {
5882+ semsg (_ (e_cannot_use_range_with_assignment_str ), p );
5883+ return FAIL ;
5884+ }
5885+ range = TRUE;
5886+ p = skipwhite (p );
5887+ if (!IS_WHITE_OR_NUL (p [-1 ]) || !IS_WHITE_OR_NUL (p [1 ]))
5888+ {
5889+ semsg (_ (e_white_space_required_before_and_after_str_at_str ),
5890+ ":" , p );
5891+ return FAIL ;
5892+ }
5893+ p = skipwhite (p + 1 );
5894+ r = compile_expr0 (& p , cctx );
5895+ }
5896+
58755897 if (r == OK && * skipwhite (p ) != ']' )
58765898 {
58775899 // this should not happen
@@ -5897,17 +5919,29 @@ compile_assign_unlet(
58975919 else
58985920 {
58995921 dest_type = lhs -> lhs_type -> tt_type ;
5922+ if (dest_type == VAR_DICT && range )
5923+ {
5924+ emsg (e_cannot_use_range_with_dictionary );
5925+ return FAIL ;
5926+ }
59005927 if (dest_type == VAR_DICT && may_generate_2STRING (-1 , cctx ) == FAIL )
59015928 return FAIL ;
5902- if (dest_type == VAR_LIST
5903- && need_type (((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ],
5929+ if (dest_type == VAR_LIST )
5930+ {
5931+ if (range
5932+ && need_type (((type_T * * )stack -> ga_data )[stack -> ga_len - 2 ],
59045933 & t_number , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
5905- return FAIL ;
5934+ return FAIL ;
5935+ if (need_type (((type_T * * )stack -> ga_data )[stack -> ga_len - 1 ],
5936+ & t_number , -1 , 0 , cctx , FALSE, FALSE) == FAIL )
5937+ return FAIL ;
5938+ }
59065939 }
59075940
59085941 // Load the dict or list. On the stack we then have:
59095942 // - value (for assignment, not for :unlet)
59105943 // - index
5944+ // - for [a : b] second index
59115945 // - variable
59125946 if (lhs -> lhs_dest == dest_expr )
59135947 {
@@ -5946,6 +5980,11 @@ compile_assign_unlet(
59465980 return FAIL ;
59475981 isn -> isn_arg .vartype = dest_type ;
59485982 }
5983+ else if (range )
5984+ {
5985+ if (generate_instr_drop (cctx , ISN_UNLETRANGE , 3 ) == NULL )
5986+ return FAIL ;
5987+ }
59495988 else
59505989 {
59515990 if (generate_instr_drop (cctx , ISN_UNLETINDEX , 2 ) == NULL )
@@ -8907,6 +8946,7 @@ delete_instr(isn_T *isn)
89078946 case ISN_TRY :
89088947 case ISN_TRYCONT :
89098948 case ISN_UNLETINDEX :
8949+ case ISN_UNLETRANGE :
89108950 case ISN_UNPACK :
89118951 // nothing allocated
89128952 break ;
0 commit comments