Mercurial > vim
diff src/vim9compile.c @ 21188:d73b6ba20053 v8.2.1145
patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Commit: https://github.com/vim/vim/commit/0ad3e894d75236915e67dfbbcc821b6bb3c05d91
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 5 21:38:11 2020 +0200
patch 8.2.1145: Vim9: "for" only accepts a list at compile time
Problem: Vim9: "for" only accepts a list at compile time.
Solution: Also accept a list at runtime.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 05 Jul 2020 21:45:04 +0200 |
parents | 96ae8622cfb6 |
children | afed2045ffc9 |
line wrap: on
line diff
--- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -6062,15 +6062,15 @@ compile_for(char_u *arg, cctx_T *cctx) return NULL; } - // now we know the type of "var" + // Now that we know the type of "var", check that it is a list, now or at + // runtime. vartype = ((type_T **)stack->ga_data)[stack->ga_len - 1]; - if (vartype->tt_type != VAR_LIST) - { - emsg(_("E1024: need a List to iterate over")); + if (need_type(vartype, &t_list_any, -1, cctx) == FAIL) + { drop_scope(cctx); return NULL; } - if (vartype->tt_member->tt_type != VAR_ANY) + if (vartype->tt_type == VAR_LIST && vartype->tt_member->tt_type != VAR_ANY) var_lvar->lv_type = vartype->tt_member; // "for_end" is set when ":endfor" is found