diff src/vim9.h @ 30333:fc0830246f49 v9.0.0502

patch 9.0.0502: a closure in a nested loop in a :def function does not work Commit: https://github.com/vim/vim/commit/cc34181f9994d64f8c8fa2f5845eaf0cc963067f Author: Bram Moolenaar <Bram@vim.org> Date: Mon Sep 19 15:54:34 2022 +0100 patch 9.0.0502: a closure in a nested loop in a :def function does not work Problem: A closure in a nested loop in a :def function does not work. Solution: Use an array of loopvars, one per loop level.
author Bram Moolenaar <Bram@vim.org>
date Mon, 19 Sep 2022 17:00:07 +0200
parents 029c59bf78f1
children ee039a6049ff
line wrap: on
line diff
--- a/src/vim9.h
+++ b/src/vim9.h
@@ -252,30 +252,31 @@ typedef enum {
 // arguments to ISN_JUMP
 typedef struct {
     jumpwhen_T	jump_when;
-    int		jump_where;	    // position to jump to
+    int		jump_where;	// position to jump to
 } jump_T;
 
 // arguments to ISN_JUMP_IF_ARG_SET
 typedef struct {
-    int		jump_arg_off;	    // argument index, negative
-    int		jump_where;	    // position to jump to
+    int		jump_arg_off;	// argument index, negative
+    int		jump_where;	// position to jump to
 } jumparg_T;
 
 // arguments to ISN_FOR
 typedef struct {
-    int	    for_idx;	    // loop variable index
-    int	    for_end;	    // position to jump to after done
+    short	for_loop_idx;	// loop variable index
+    int		for_end;	// position to jump to after done
 } forloop_T;
 
 // arguments to ISN_WHILE
 typedef struct {
-    int	    while_funcref_idx;  // variable index for funcref count
-    int	    while_end;		// position to jump to after done
+    short	while_funcref_idx;  // variable index for funcref count
+    int		while_end;	    // position to jump to after done
 } whileloop_T;
 
 // arguments to ISN_ENDLOOP
 typedef struct {
     short    end_funcref_idx;	// variable index of funcrefs.ga_len
+    short    end_depth;		// nested loop depth
     short    end_var_idx;	// first variable declared in the loop
     short    end_var_count;	// number of variables declared in the loop
 } endloop_T;
@@ -356,9 +357,8 @@ typedef struct {
 
 // extra arguments for funcref_T
 typedef struct {
-    char_u	*fre_func_name;	    // function name for legacy function
-    short	fre_loop_var_idx;   // index of first variable inside loop
-    short	fre_loop_var_count; // number of variables inside loop
+    char_u	  *fre_func_name;	// function name for legacy function
+    loopvarinfo_T fre_loopvar_info;	// info about variables inside loops
 } funcref_extra_T;
 
 // arguments to ISN_FUNCREF
@@ -369,10 +369,9 @@ typedef struct {
 
 // arguments to ISN_NEWFUNC
 typedef struct {
-    char_u	*nfa_lambda;	   // name of the lambda already defined
-    char_u	*nfa_global;	   // name of the global function to be created
-    short	nfa_loop_var_idx;    // index of first variable inside loop
-    short	nfa_loop_var_count;  // number of variables inside loop
+    char_u	  *nfa_lambda;	    // name of the lambda already defined
+    char_u	  *nfa_global;	    // name of the global function to be created
+    loopvarinfo_T nfa_loopvar_info; // ifno about variables inside loops
 } newfuncarg_T;
 
 typedef struct {
@@ -628,6 +627,7 @@ typedef struct {
     int	    li_local_count;	    // ctx_locals.ga_len at loop start
     int	    li_closure_count;	    // ctx_closure_count at loop start
     int	    li_funcref_idx;	    // index of var that holds funcref count
+    int	    li_depth;		    // nested loop depth
 } loop_info_T;
 
 /*
@@ -678,6 +678,7 @@ struct scope_S {
     scopetype_T se_type;
     int		se_local_count;	    // ctx_locals.ga_len before scope
     skip_T	se_skip_save;	    // ctx_skip before the block
+    int		se_loop_depth;	    // number of loop scopes, including this
     union {
 	ifscope_T	se_if;
 	whilescope_T	se_while;
@@ -693,6 +694,7 @@ typedef struct {
     char_u	*lv_name;
     type_T	*lv_type;
     int		lv_idx;		// index of the variable on the stack
+    int		lv_loop_depth;	// depth for variable inside a loop or -1
     int		lv_loop_idx;	// index of first variable inside a loop or -1
     int		lv_from_outer;	// nesting level, using ctx_outer scope
     int		lv_const;	// when TRUE cannot be assigned to