Mercurial > vim
comparison src/vim9compile.c @ 26346:8be6413a8e27 v8.2.3704
patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Commit: https://github.com/vim/vim/commit/ab36e6ae7b87b0295fb19270e4339a734875c6b1
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Nov 30 16:14:49 2021 +0000
patch 8.2.3704: Vim9: cannot use a list declaration in a :def function
Problem: Vim9: cannot use a list declaration in a :def function.
Solution: Make it work.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 30 Nov 2021 17:15:03 +0100 |
parents | 4044306e3836 |
children | f209f28ad898 |
comparison
equal
deleted
inserted
replaced
26345:1707aa6d46a2 | 26346:8be6413a8e27 |
---|---|
142 // "[expr]" or ".name" for :redir | 142 // "[expr]" or ".name" for :redir |
143 size_t lhs_varlen_total; // length of the variable including | 143 size_t lhs_varlen_total; // length of the variable including |
144 // any "[expr]" or ".name" | 144 // any "[expr]" or ".name" |
145 char_u *lhs_dest_end; // end of the destination, including | 145 char_u *lhs_dest_end; // end of the destination, including |
146 // "[expr]" or ".name". | 146 // "[expr]" or ".name". |
147 char_u *lhs_end; // end including any type | |
147 | 148 |
148 int lhs_has_index; // has "[expr]" or ".name" | 149 int lhs_has_index; // has "[expr]" or ".name" |
149 | 150 |
150 int lhs_new_local; // create new local variable | 151 int lhs_new_local; // create new local variable |
151 int lhs_opt_flags; // for when destination is an option | 152 int lhs_opt_flags; // for when destination is an option |
6297 if (is_decl && lhs->lhs_dest_end == var_start + 2 | 6298 if (is_decl && lhs->lhs_dest_end == var_start + 2 |
6298 && lhs->lhs_dest_end[-1] == ':') | 6299 && lhs->lhs_dest_end[-1] == ':') |
6299 --lhs->lhs_dest_end; | 6300 --lhs->lhs_dest_end; |
6300 if (is_decl && var_end == var_start + 2 && var_end[-1] == ':') | 6301 if (is_decl && var_end == var_start + 2 && var_end[-1] == ':') |
6301 --var_end; | 6302 --var_end; |
6303 lhs->lhs_end = lhs->lhs_dest_end; | |
6302 | 6304 |
6303 // compute the length of the destination without "[expr]" or ".name" | 6305 // compute the length of the destination without "[expr]" or ".name" |
6304 lhs->lhs_varlen = var_end - var_start; | 6306 lhs->lhs_varlen = var_end - var_start; |
6305 lhs->lhs_varlen_total = lhs->lhs_varlen; | 6307 lhs->lhs_varlen_total = lhs->lhs_varlen; |
6306 lhs->lhs_name = vim_strnsave(var_start, lhs->lhs_varlen); | 6308 lhs->lhs_name = vim_strnsave(var_start, lhs->lhs_varlen); |
6433 vim9_declare_error(lhs->lhs_name); | 6435 vim9_declare_error(lhs->lhs_name); |
6434 return FAIL; | 6436 return FAIL; |
6435 } | 6437 } |
6436 } | 6438 } |
6437 | 6439 |
6438 // handle "a:name" as a name, not index "name" on "a" | 6440 // handle "a:name" as a name, not index "name" in "a" |
6439 if (lhs->lhs_varlen > 1 || var_start[lhs->lhs_varlen] != ':') | 6441 if (lhs->lhs_varlen > 1 || var_start[lhs->lhs_varlen] != ':') |
6440 var_end = lhs->lhs_dest_end; | 6442 var_end = lhs->lhs_dest_end; |
6441 | 6443 |
6442 if (lhs->lhs_dest != dest_option) | 6444 if (lhs->lhs_dest != dest_option) |
6443 { | 6445 { |
6454 p = skipwhite(var_end + 1); | 6456 p = skipwhite(var_end + 1); |
6455 lhs->lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE); | 6457 lhs->lhs_type = parse_type(&p, cctx->ctx_type_list, TRUE); |
6456 if (lhs->lhs_type == NULL) | 6458 if (lhs->lhs_type == NULL) |
6457 return FAIL; | 6459 return FAIL; |
6458 lhs->lhs_has_type = TRUE; | 6460 lhs->lhs_has_type = TRUE; |
6461 lhs->lhs_end = p; | |
6459 } | 6462 } |
6460 else if (lhs->lhs_lvar != NULL) | 6463 else if (lhs->lhs_lvar != NULL) |
6461 lhs->lhs_type = lhs->lhs_lvar->lv_type; | 6464 lhs->lhs_type = lhs->lhs_lvar->lv_type; |
6462 } | 6465 } |
6463 | 6466 |
6894 // Skip over the "var" or "[var, var]" to get to any "=". | 6897 // Skip over the "var" or "[var, var]" to get to any "=". |
6895 p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE); | 6898 p = skip_var_list(arg, TRUE, &var_count, &semicolon, TRUE); |
6896 if (p == NULL) | 6899 if (p == NULL) |
6897 return *arg == '[' ? arg : NULL; | 6900 return *arg == '[' ? arg : NULL; |
6898 | 6901 |
6899 if (var_count > 0 && is_decl) | |
6900 { | |
6901 // TODO: should we allow this, and figure out type inference from list | |
6902 // members? | |
6903 emsg(_(e_cannot_use_list_for_declaration)); | |
6904 return NULL; | |
6905 } | |
6906 lhs.lhs_name = NULL; | 6902 lhs.lhs_name = NULL; |
6907 | 6903 |
6908 sp = p; | 6904 sp = p; |
6909 p = skipwhite(p); | 6905 p = skipwhite(p); |
6910 op = p; | 6906 op = p; |
7328 } | 7324 } |
7329 } | 7325 } |
7330 cctx->ctx_lnum = save_lnum; | 7326 cctx->ctx_lnum = save_lnum; |
7331 | 7327 |
7332 if (var_idx + 1 < var_count) | 7328 if (var_idx + 1 < var_count) |
7333 var_start = skipwhite(lhs.lhs_dest_end + 1); | 7329 var_start = skipwhite(lhs.lhs_end + 1); |
7334 } | 7330 } |
7335 | 7331 |
7336 // For "[var, var] = expr" drop the "expr" value. | 7332 // For "[var, var] = expr" drop the "expr" value. |
7337 // Also for "[var, var; _] = expr". | 7333 // Also for "[var, var; _] = expr". |
7338 if (var_count > 0 && (!semicolon || !did_generate_slice)) | 7334 if (var_count > 0 && (!semicolon || !did_generate_slice)) |