0
0
mirror of https://github.com/vim/vim.git synced 2025-09-24 03:44:06 -04:00

patch 8.2.2658: :for cannot loop over a string

Problem:    :for cannot loop over a string.
Solution:   Accept a string argument and iterate over its characters.
This commit is contained in:
Bram Moolenaar
2021-03-26 20:41:29 +01:00
parent 522eefd9a2
commit 74e54fcb44
9 changed files with 164 additions and 33 deletions

View File

@@ -7264,11 +7264,15 @@ compile_for(char_u *arg_start, cctx_T *cctx)
}
arg_end = arg;
// Now that we know the type of "var", check that it is a list, now or at
// runtime.
// If we know the type of "var" and it is a not a list or string we can
// give an error now.
vartype = ((type_T **)stack->ga_data)[stack->ga_len - 1];
if (need_type(vartype, &t_list_any, -1, 0, cctx, FALSE, FALSE) == FAIL)
if (vartype->tt_type != VAR_LIST && vartype->tt_type != VAR_STRING
&& vartype->tt_type != VAR_ANY)
{
// TODO: support Blob
semsg(_(e_for_loop_on_str_not_supported),
vartype_name(vartype->tt_type));
drop_scope(cctx);
return NULL;
}