Mercurial > vim
comparison src/vim9execute.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 | 21c552fb7da5 |
children | e3f9528bddda |
comparison
equal
deleted
inserted
replaced
21830:bef87368c676 | 21831:d8422de73113 |
---|---|
2239 char_u *res; | 2239 char_u *res; |
2240 | 2240 |
2241 // string index: string is at stack-2, index at stack-1 | 2241 // string index: string is at stack-2, index at stack-1 |
2242 // string slice: string is at stack-3, first index at | 2242 // string slice: string is at stack-3, first index at |
2243 // stack-2, second index at stack-1 | 2243 // stack-2, second index at stack-1 |
2244 tv = is_slice ? STACK_TV_BOT(-3) : STACK_TV_BOT(-2); | |
2245 if (tv->v_type != VAR_STRING) | |
2246 { | |
2247 SOURCING_LNUM = iptr->isn_lnum; | |
2248 emsg(_(e_stringreq)); | |
2249 goto on_error; | |
2250 } | |
2251 | |
2252 if (is_slice) | 2244 if (is_slice) |
2253 { | 2245 { |
2254 tv = STACK_TV_BOT(-2); | 2246 tv = STACK_TV_BOT(-2); |
2255 if (tv->v_type != VAR_NUMBER) | |
2256 { | |
2257 SOURCING_LNUM = iptr->isn_lnum; | |
2258 emsg(_(e_number_exp)); | |
2259 goto on_error; | |
2260 } | |
2261 n1 = tv->vval.v_number; | 2247 n1 = tv->vval.v_number; |
2262 } | 2248 } |
2263 | 2249 |
2264 tv = STACK_TV_BOT(-1); | 2250 tv = STACK_TV_BOT(-1); |
2265 if (tv->v_type != VAR_NUMBER) | |
2266 { | |
2267 SOURCING_LNUM = iptr->isn_lnum; | |
2268 emsg(_(e_number_exp)); | |
2269 goto on_error; | |
2270 } | |
2271 n2 = tv->vval.v_number; | 2251 n2 = tv->vval.v_number; |
2272 | 2252 |
2273 ectx.ec_stack.ga_len -= is_slice ? 2 : 1; | 2253 ectx.ec_stack.ga_len -= is_slice ? 2 : 1; |
2274 tv = STACK_TV_BOT(-1); | 2254 tv = STACK_TV_BOT(-1); |
2275 if (is_slice) | 2255 if (is_slice) |
2294 | 2274 |
2295 // list index: list is at stack-2, index at stack-1 | 2275 // list index: list is at stack-2, index at stack-1 |
2296 // list slice: list is at stack-3, indexes at stack-2 and | 2276 // list slice: list is at stack-3, indexes at stack-2 and |
2297 // stack-1 | 2277 // stack-1 |
2298 tv = is_slice ? STACK_TV_BOT(-3) : STACK_TV_BOT(-2); | 2278 tv = is_slice ? STACK_TV_BOT(-3) : STACK_TV_BOT(-2); |
2299 if (tv->v_type != VAR_LIST) | |
2300 { | |
2301 SOURCING_LNUM = iptr->isn_lnum; | |
2302 emsg(_(e_listreq)); | |
2303 goto on_error; | |
2304 } | |
2305 list = tv->vval.v_list; | 2279 list = tv->vval.v_list; |
2306 | 2280 |
2307 tv = STACK_TV_BOT(-1); | 2281 tv = STACK_TV_BOT(-1); |
2308 if (tv->v_type != VAR_NUMBER) | |
2309 { | |
2310 SOURCING_LNUM = iptr->isn_lnum; | |
2311 emsg(_(e_number_exp)); | |
2312 goto on_error; | |
2313 } | |
2314 n1 = n2 = tv->vval.v_number; | 2282 n1 = n2 = tv->vval.v_number; |
2315 clear_tv(tv); | 2283 clear_tv(tv); |
2316 | 2284 |
2317 if (is_slice) | 2285 if (is_slice) |
2318 { | 2286 { |
2319 tv = STACK_TV_BOT(-2); | 2287 tv = STACK_TV_BOT(-2); |
2320 if (tv->v_type != VAR_NUMBER) | |
2321 { | |
2322 SOURCING_LNUM = iptr->isn_lnum; | |
2323 emsg(_(e_number_exp)); | |
2324 goto on_error; | |
2325 } | |
2326 n1 = tv->vval.v_number; | 2288 n1 = tv->vval.v_number; |
2327 clear_tv(tv); | 2289 clear_tv(tv); |
2328 } | 2290 } |
2329 | 2291 |
2330 ectx.ec_stack.ga_len -= is_slice ? 2 : 1; | 2292 ectx.ec_stack.ga_len -= is_slice ? 2 : 1; |