comparison src/vim9compile.c @ 21831:d8422de73113 v8.2.1465

patch 8.2.1465: Vim9: subscript not handled properly Commit: https://github.com/vim/vim/commit/56acb0943ede35cd9d2f6667cde2442819ccbf59 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 16 14:48:19 2020 +0200 patch 8.2.1465: Vim9: subscript not handled properly Problem: Vim9: subscript not handled properly. Solution: Adjust error message. Remove dead code. Disallow string to number conversion in scripts.
author Bram Moolenaar <Bram@vim.org>
date Sun, 16 Aug 2020 15:00:05 +0200
parents af5db9b6d210
children e3f9528bddda
comparison
equal deleted inserted replaced
21830:bef87368c676 21831:d8422de73113
3065 } 3065 }
3066 else if (**arg == '[') 3066 else if (**arg == '[')
3067 { 3067 {
3068 garray_T *stack = &cctx->ctx_type_stack; 3068 garray_T *stack = &cctx->ctx_type_stack;
3069 type_T **typep; 3069 type_T **typep;
3070 type_T *valtype;
3070 vartype_T vtype; 3071 vartype_T vtype;
3071 int is_slice = FALSE; 3072 int is_slice = FALSE;
3072 3073
3073 // list index: list[123] 3074 // list index: list[123]
3074 // dict member: dict[key] 3075 // dict member: dict[key]
3125 // TODO: If we don't know use an instruction to figure it out at 3126 // TODO: If we don't know use an instruction to figure it out at
3126 // runtime. 3127 // runtime.
3127 typep = ((type_T **)stack->ga_data) + stack->ga_len 3128 typep = ((type_T **)stack->ga_data) + stack->ga_len
3128 - (is_slice ? 3 : 2); 3129 - (is_slice ? 3 : 2);
3129 vtype = (*typep)->tt_type; 3130 vtype = (*typep)->tt_type;
3130 if (*typep == &t_any) 3131 valtype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
3131 { 3132 // If the index is a string, the variable must be a Dict.
3132 type_T *valtype = ((type_T **)stack->ga_data) 3133 if (*typep == &t_any && valtype == &t_string)
3133 [stack->ga_len - 1]; 3134 vtype = VAR_DICT;
3134 if (valtype == &t_string) 3135 if (vtype == VAR_STRING || vtype == VAR_LIST || vtype == VAR_BLOB)
3135 vtype = VAR_DICT; 3136 {
3136 } 3137 if (need_type(valtype, &t_number, -1, cctx, FALSE) == FAIL)
3138 return FAIL;
3139 if (is_slice)
3140 {
3141 valtype = ((type_T **)stack->ga_data)[stack->ga_len - 2];
3142 if (need_type(valtype, &t_number, -2, cctx, FALSE) == FAIL)
3143 return FAIL;
3144 }
3145 }
3146
3137 if (vtype == VAR_DICT) 3147 if (vtype == VAR_DICT)
3138 { 3148 {
3139 if (is_slice) 3149 if (is_slice)
3140 { 3150 {
3141 emsg(_(e_cannot_slice_dictionary)); 3151 emsg(_(e_cannot_slice_dictionary));
3167 emsg("Sorry, blob index and slice not implemented yet"); 3177 emsg("Sorry, blob index and slice not implemented yet");
3168 return FAIL; 3178 return FAIL;
3169 } 3179 }
3170 else if (vtype == VAR_LIST || *typep == &t_any) 3180 else if (vtype == VAR_LIST || *typep == &t_any)
3171 { 3181 {
3182 // TODO: any requires runtime code
3183 if (*typep == &t_any && need_type(*typep, &t_list_any,
3184 is_slice ? -3 : -2, cctx, FALSE) == FAIL)
3185 return FAIL;
3172 if (is_slice) 3186 if (is_slice)
3173 { 3187 {
3174 if (generate_instr_drop(cctx, ISN_LISTSLICE, 2) == FAIL) 3188 if (generate_instr_drop(cctx, ISN_LISTSLICE, 2) == FAIL)
3175 return FAIL; 3189 return FAIL;
3176 } 3190 }
3182 return FAIL; 3196 return FAIL;
3183 } 3197 }
3184 } 3198 }
3185 else 3199 else
3186 { 3200 {
3187 emsg(_(e_list_dict_or_blob_required)); 3201 emsg(_(e_string_list_dict_or_blob_required));
3188 return FAIL; 3202 return FAIL;
3189 } 3203 }
3190 } 3204 }
3191 else if (*p == '.' && p[1] != '.') 3205 else if (*p == '.' && p[1] != '.')
3192 { 3206 {