Mercurial > vim
comparison src/vim9compile.c @ 20871:65d9189d4dca v8.2.0987
patch 8.2.0987: Vim9: cannot assign to [var; var]
Commit: https://github.com/vim/vim/commit/9af78769eeae0318e07aa8b6af4d6e2244481ca7
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Jun 16 11:34:42 2020 +0200
patch 8.2.0987: Vim9: cannot assign to [var; var]
Problem: Vim9: cannot assign to [var; var].
Solution: Assign rest of items to a list.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 16 Jun 2020 11:45:04 +0200 |
parents | 876e16c48bd1 |
children | e76bddcf3341 |
comparison
equal
deleted
inserted
replaced
20870:6203fd2cfb51 | 20871:65d9189d4dca |
---|---|
1080 // add the item type to the type stack | 1080 // add the item type to the type stack |
1081 if (ga_grow(stack, 1) == FAIL) | 1081 if (ga_grow(stack, 1) == FAIL) |
1082 return FAIL; | 1082 return FAIL; |
1083 ((type_T **)stack->ga_data)[stack->ga_len] = item_type; | 1083 ((type_T **)stack->ga_data)[stack->ga_len] = item_type; |
1084 ++stack->ga_len; | 1084 ++stack->ga_len; |
1085 return OK; | |
1086 } | |
1087 | |
1088 /* | |
1089 * Generate an ISN_SLICE instruction with "count". | |
1090 */ | |
1091 static int | |
1092 generate_SLICE(cctx_T *cctx, int count) | |
1093 { | |
1094 isn_T *isn; | |
1095 | |
1096 RETURN_OK_IF_SKIP(cctx); | |
1097 if ((isn = generate_instr(cctx, ISN_SLICE)) == NULL) | |
1098 return FAIL; | |
1099 isn->isn_arg.number = count; | |
1100 return OK; | |
1101 } | |
1102 | |
1103 /* | |
1104 * Generate an ISN_CHECKLEN instruction with "min_len". | |
1105 */ | |
1106 static int | |
1107 generate_CHECKLEN(cctx_T *cctx, int min_len, int more_OK) | |
1108 { | |
1109 isn_T *isn; | |
1110 | |
1111 RETURN_OK_IF_SKIP(cctx); | |
1112 | |
1113 if ((isn = generate_instr(cctx, ISN_CHECKLEN)) == NULL) | |
1114 return FAIL; | |
1115 isn->isn_arg.checklen.cl_min_len = min_len; | |
1116 isn->isn_arg.checklen.cl_more_OK = more_OK; | |
1117 | |
1085 return OK; | 1118 return OK; |
1086 } | 1119 } |
1087 | 1120 |
1088 /* | 1121 /* |
1089 * Generate an ISN_STORE instruction. | 1122 * Generate an ISN_STORE instruction. |
4706 emsg(_(e_cannot_use_void)); | 4739 emsg(_(e_cannot_use_void)); |
4707 goto theend; | 4740 goto theend; |
4708 } | 4741 } |
4709 if (need_type(stacktype, &t_list_any, -1, cctx) == FAIL) | 4742 if (need_type(stacktype, &t_list_any, -1, cctx) == FAIL) |
4710 goto theend; | 4743 goto theend; |
4711 // TODO: check length of list to be var_count (or more if | 4744 generate_CHECKLEN(cctx, semicolon ? var_count - 1 : var_count, |
4712 // "semicolon" set) | 4745 semicolon); |
4713 } | 4746 } |
4714 } | 4747 } |
4715 | 4748 |
4716 /* | 4749 /* |
4717 * Loop over variables in "[var, var] = expr". | 4750 * Loop over variables in "[var, var] = expr". |
5064 if (new_local) | 5097 if (new_local) |
5065 ++cctx->ctx_locals.ga_len; | 5098 ++cctx->ctx_locals.ga_len; |
5066 if (r == FAIL) | 5099 if (r == FAIL) |
5067 goto theend; | 5100 goto theend; |
5068 } | 5101 } |
5102 else if (semicolon && var_idx == var_count - 1) | |
5103 { | |
5104 // For "[var; var] = expr" get the rest of the list | |
5105 if (generate_SLICE(cctx, var_count - 1) == FAIL) | |
5106 goto theend; | |
5107 } | |
5069 else | 5108 else |
5070 { | 5109 { |
5071 // For "[var, var] = expr" get the "var_idx" item from the | 5110 // For "[var, var] = expr" get the "var_idx" item from the |
5072 // list. | 5111 // list. |
5073 if (generate_GETITEM(cctx, var_idx) == FAIL) | 5112 if (generate_GETITEM(cctx, var_idx) == FAIL) |
5371 if (var_idx + 1 < var_count) | 5410 if (var_idx + 1 < var_count) |
5372 var_start = skipwhite(var_end + 1); | 5411 var_start = skipwhite(var_end + 1); |
5373 } | 5412 } |
5374 | 5413 |
5375 // for "[var, var] = expr" drop the "expr" value | 5414 // for "[var, var] = expr" drop the "expr" value |
5376 if (var_count > 0 && generate_instr_drop(cctx, ISN_DROP, 1) == NULL) | 5415 if (var_count > 0 && !semicolon) |
5377 goto theend; | 5416 { |
5417 if (generate_instr_drop(cctx, ISN_DROP, 1) == NULL) | |
5418 goto theend; | |
5419 } | |
5378 | 5420 |
5379 ret = end; | 5421 ret = end; |
5380 | 5422 |
5381 theend: | 5423 theend: |
5382 vim_free(name); | 5424 vim_free(name); |
7071 case ISN_ADDLIST: | 7113 case ISN_ADDLIST: |
7072 case ISN_BCALL: | 7114 case ISN_BCALL: |
7073 case ISN_CATCH: | 7115 case ISN_CATCH: |
7074 case ISN_CHECKNR: | 7116 case ISN_CHECKNR: |
7075 case ISN_CHECKTYPE: | 7117 case ISN_CHECKTYPE: |
7118 case ISN_CHECKLEN: | |
7076 case ISN_COMPAREANY: | 7119 case ISN_COMPAREANY: |
7077 case ISN_COMPAREBLOB: | 7120 case ISN_COMPAREBLOB: |
7078 case ISN_COMPAREBOOL: | 7121 case ISN_COMPAREBOOL: |
7079 case ISN_COMPAREDICT: | 7122 case ISN_COMPAREDICT: |
7080 case ISN_COMPAREFLOAT: | 7123 case ISN_COMPAREFLOAT: |
7093 case ISN_EXECCONCAT: | 7136 case ISN_EXECCONCAT: |
7094 case ISN_EXECUTE: | 7137 case ISN_EXECUTE: |
7095 case ISN_FOR: | 7138 case ISN_FOR: |
7096 case ISN_INDEX: | 7139 case ISN_INDEX: |
7097 case ISN_GETITEM: | 7140 case ISN_GETITEM: |
7141 case ISN_SLICE: | |
7098 case ISN_MEMBER: | 7142 case ISN_MEMBER: |
7099 case ISN_JUMP: | 7143 case ISN_JUMP: |
7100 case ISN_LOAD: | 7144 case ISN_LOAD: |
7101 case ISN_LOADOUTER: | 7145 case ISN_LOADOUTER: |
7102 case ISN_LOADSCRIPT: | 7146 case ISN_LOADSCRIPT: |