Mercurial > vim
diff src/vim9compile.c @ 24234:7ffc795288dd v8.2.2658
patch 8.2.2658: :for cannot loop over a string
Commit: https://github.com/vim/vim/commit/74e54fcb447e5db32f9c2df34c0554bbecdccca2
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Mar 26 20:41:29 2021 +0100
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.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 26 Mar 2021 20:45:02 +0100 |
parents | a2e6029d354e |
children | d0e86f1b34e7 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -7264,11 +7264,15 @@ compile_for(char_u *arg_start, cctx_T *c } 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; }