Mercurial > vim
comparison src/vim9compile.c @ 24097:26d3c1539bcc v8.2.2590
patch 8.2.2590: Vim9: default argument value may cause internal error
Commit: https://github.com/vim/vim/commit/12bce95887f7c5f07a7bdb7b4485b53d074ccc0a
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 11 20:04:04 2021 +0100
patch 8.2.2590: Vim9: default argument value may cause internal error
Problem: Vim9: default argument value may cause internal error.
Solution: Hide later function arguments when compiling the expression.
(closes #7948)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 11 Mar 2021 20:15:05 +0100 |
parents | 92139c21cdfd |
children | a028cb6898a2 |
comparison
equal
deleted
inserted
replaced
24096:8c4686919942 | 24097:26d3c1539bcc |
---|---|
8197 | 8197 |
8198 if (ufunc->uf_def_args.ga_len > 0) | 8198 if (ufunc->uf_def_args.ga_len > 0) |
8199 { | 8199 { |
8200 int count = ufunc->uf_def_args.ga_len; | 8200 int count = ufunc->uf_def_args.ga_len; |
8201 int first_def_arg = ufunc->uf_args.ga_len - count; | 8201 int first_def_arg = ufunc->uf_args.ga_len - count; |
8202 int uf_args_len = ufunc->uf_args.ga_len; | |
8202 int i; | 8203 int i; |
8203 char_u *arg; | 8204 char_u *arg; |
8204 int off = STACK_FRAME_SIZE + (ufunc->uf_va_name != NULL ? 1 : 0); | 8205 int off = STACK_FRAME_SIZE + (ufunc->uf_va_name != NULL ? 1 : 0); |
8205 int did_set_arg_type = FALSE; | 8206 int did_set_arg_type = FALSE; |
8206 | 8207 |
8209 // where to start when the function is called, depending on the number | 8210 // where to start when the function is called, depending on the number |
8210 // of arguments. | 8211 // of arguments. |
8211 ufunc->uf_def_arg_idx = ALLOC_CLEAR_MULT(int, count + 1); | 8212 ufunc->uf_def_arg_idx = ALLOC_CLEAR_MULT(int, count + 1); |
8212 if (ufunc->uf_def_arg_idx == NULL) | 8213 if (ufunc->uf_def_arg_idx == NULL) |
8213 goto erret; | 8214 goto erret; |
8215 SOURCING_LNUM = 0; // line number unknown | |
8214 for (i = 0; i < count; ++i) | 8216 for (i = 0; i < count; ++i) |
8215 { | 8217 { |
8216 garray_T *stack = &cctx.ctx_type_stack; | 8218 garray_T *stack = &cctx.ctx_type_stack; |
8217 type_T *val_type; | 8219 type_T *val_type; |
8218 int arg_idx = first_def_arg + i; | 8220 int arg_idx = first_def_arg + i; |
8219 where_T where; | 8221 where_T where; |
8222 int r; | |
8223 | |
8224 // Make sure later arguments are not found. | |
8225 ufunc->uf_args.ga_len = i; | |
8220 | 8226 |
8221 ufunc->uf_def_arg_idx[i] = instr->ga_len; | 8227 ufunc->uf_def_arg_idx[i] = instr->ga_len; |
8222 arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i]; | 8228 arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i]; |
8223 if (compile_expr0(&arg, &cctx) == FAIL) | 8229 r = compile_expr0(&arg, &cctx); |
8230 | |
8231 ufunc->uf_args.ga_len = uf_args_len; | |
8232 if (r == FAIL) | |
8224 goto erret; | 8233 goto erret; |
8225 | 8234 |
8226 // If no type specified use the type of the default value. | 8235 // If no type specified use the type of the default value. |
8227 // Otherwise check that the default value type matches the | 8236 // Otherwise check that the default value type matches the |
8228 // specified type. | 8237 // specified type. |