diff 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
line wrap: on
line diff
--- a/src/vim9compile.c
+++ b/src/vim9compile.c
@@ -8199,6 +8199,7 @@ compile_def_function(
     {
 	int	count = ufunc->uf_def_args.ga_len;
 	int	first_def_arg = ufunc->uf_args.ga_len - count;
+	int	uf_args_len = ufunc->uf_args.ga_len;
 	int	i;
 	char_u	*arg;
 	int	off = STACK_FRAME_SIZE + (ufunc->uf_va_name != NULL ? 1 : 0);
@@ -8211,16 +8212,24 @@ compile_def_function(
 	ufunc->uf_def_arg_idx = ALLOC_CLEAR_MULT(int, count + 1);
 	if (ufunc->uf_def_arg_idx == NULL)
 	    goto erret;
+	SOURCING_LNUM = 0;  // line number unknown
 	for (i = 0; i < count; ++i)
 	{
 	    garray_T	*stack = &cctx.ctx_type_stack;
 	    type_T	*val_type;
 	    int		arg_idx = first_def_arg + i;
 	    where_T	where;
+	    int		r;
+
+	    // Make sure later arguments are not found.
+	    ufunc->uf_args.ga_len = i;
 
 	    ufunc->uf_def_arg_idx[i] = instr->ga_len;
 	    arg = ((char_u **)(ufunc->uf_def_args.ga_data))[i];
-	    if (compile_expr0(&arg, &cctx) == FAIL)
+	    r = compile_expr0(&arg, &cctx);
+
+	    ufunc->uf_args.ga_len = uf_args_len;
+	    if (r == FAIL)
 		goto erret;
 
 	    // If no type specified use the type of the default value.