diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-11-16 22:11:49 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-11-16 22:11:49 +0100 |
commit | fc74d03e7694bac3b50d8d6b6b78b40a71818744 (patch) | |
tree | 3d512403ad1acba51cef301efcc8aa3dd9d665de /src/vim9compile.c | |
parent | e6329e4c55cd81b6134820eab6a10b02c11c1277 (diff) | |
download | vim-git-fc74d03e7694bac3b50d8d6b6b78b40a71818744.tar.gz |
patch 8.2.2000: Vim9: dict.key assignment not implemented yetv8.2.2000
Problem: Vim9: dict.key assignment not implemented yet.
Solution: Implement dict.key assignment. (closes #7312)
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r-- | src/vim9compile.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c index 8dc974422..6b2b766be 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -5384,14 +5384,14 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx) member_type = type; if (var_end > var_start + varlen) { - // Something follows after the variable: "var[idx]". + // Something follows after the variable: "var[idx]" or "var.key". if (is_decl) { emsg(_(e_cannot_use_index_when_declaring_variable)); goto theend; } - if (var_start[varlen] == '[') + if (var_start[varlen] == '[' || var_start[varlen] == '.') { has_index = TRUE; if (type->tt_member == NULL) @@ -5635,21 +5635,33 @@ compile_assignment(char_u *arg, exarg_T *eap, cmdidx_T cmdidx, cctx_T *cctx) { int r; - // Compile the "idx" in "var[idx]". + // Compile the "idx" in "var[idx]" or "key" in "var.key". if (new_local) --cctx->ctx_locals.ga_len; - p = skipwhite(var_start + varlen + 1); - r = compile_expr0(&p, cctx); + p = var_start + varlen; + if (*p == '[') + { + p = skipwhite(p + 1); + r = compile_expr0(&p, cctx); + if (r == OK && *skipwhite(p) != ']') + { + // this should not happen + emsg(_(e_missbrac)); + r = FAIL; + } + } + else // if (*p == '.') + { + char_u *key_end = to_name_end(p + 1, TRUE); + char_u *key = vim_strnsave(p + 1, key_end - p - 1); + + r = generate_PUSHS(cctx, key); + } if (new_local) ++cctx->ctx_locals.ga_len; if (r == FAIL) goto theend; - if (*skipwhite(p) != ']') - { - // this should not happen - emsg(_(e_missbrac)); - goto theend; - } + if (type == &t_any) { type_T *idx_type = ((type_T **)stack->ga_data)[ |