Mercurial > vim
diff src/vim9compile.c @ 21393:320581a133d9 v8.2.1247
patch 8.2.1247: Vim9: cannot index a character in a string
Commit: https://github.com/vim/vim/commit/bf9d8c3765a5255c0a0b577ca2e25d70a8bcb688
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 19 17:55:44 2020 +0200
patch 8.2.1247: Vim9: cannot index a character in a string
Problem: Vim9: cannot index a character in a string.
Solution: Add ISN_STRINDEX instruction. (closes https://github.com/vim/vim/issues/6478)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Jul 2020 18:00:04 +0200 |
parents | 8b882afa8ed2 |
children | 5cb6e676defd |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -3752,6 +3752,7 @@ compile_subscript( // list index: list[123] // dict member: dict[key] + // string index: text[123] // TODO: blob index // TODO: more arguments // TODO: recognize list or dict at runtime @@ -3799,11 +3800,17 @@ compile_subscript( if (generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL) return FAIL; } + else if (vtype == VAR_STRING) + { + *typep = &t_number; + if (generate_instr_drop(cctx, ISN_STRINDEX, 1) == FAIL) + return FAIL; + } else if (vtype == VAR_LIST || *typep == &t_any) { if ((*typep)->tt_type == VAR_LIST) *typep = (*typep)->tt_member; - if (generate_instr_drop(cctx, ISN_INDEX, 1) == FAIL) + if (generate_instr_drop(cctx, ISN_LISTINDEX, 1) == FAIL) return FAIL; } else @@ -7542,7 +7549,8 @@ delete_instr(isn_T *isn) case ISN_EXECCONCAT: case ISN_EXECUTE: case ISN_FOR: - case ISN_INDEX: + case ISN_LISTINDEX: + case ISN_STRINDEX: case ISN_GETITEM: case ISN_SLICE: case ISN_MEMBER: