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 #6478)
diff --git a/src/vim9compile.c b/src/vim9compile.c
index 31cb31e..a9db1d0 100644
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -3752,6 +3752,7 @@
// 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 @@
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 @@
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: