patch 8.2.1846: Vim9: block variables are not found in compiled function

Problem:    Vim9: variables declared in a local block are not found in
            when a function is compiled.
Solution:   Look for script variables in sn_all_vars.
diff --git a/src/userfunc.c b/src/userfunc.c
index 39d8fb2..2e33d60 100644
--- a/src/userfunc.c
+++ b/src/userfunc.c
@@ -1134,6 +1134,7 @@
     ga_clear_strings(&(fp->uf_lines));
     VIM_CLEAR(fp->uf_arg_types);
     VIM_CLEAR(fp->uf_def_arg_idx);
+    VIM_CLEAR(fp->uf_block_ids);
     VIM_CLEAR(fp->uf_va_name);
     clear_type_list(&fp->uf_type_list);
 
@@ -2658,7 +2659,7 @@
  * Returns a pointer to the function or NULL if no function defined.
  */
     ufunc_T *
-def_function(exarg_T *eap, char_u *name_arg)
+define_function(exarg_T *eap, char_u *name_arg)
 {
     char_u	*theline;
     char_u	*line_to_free = NULL;
@@ -3477,9 +3478,24 @@
 	// error messages are for the first function line
 	SOURCING_LNUM = sourcing_lnum_top;
 
+	if (eap->cstack != NULL && eap->cstack->cs_idx >= 0)
+	{
+	    int count = eap->cstack->cs_idx + 1;
+
+	    // The block context may be needed for script variables declared in
+	    // a block visible now but not when the function is compiled.
+	    fp->uf_block_ids = ALLOC_MULT(int, count);
+	    if (fp->uf_block_ids != NULL)
+	    {
+		mch_memmove(fp->uf_block_ids, eap->cstack->cs_block_id,
+							  sizeof(int) * count);
+		fp->uf_block_depth = count;
+	    }
+	    // TODO: set flag in each block to indicate a function was defined
+	}
+
 	// parse the argument types
 	ga_init2(&fp->uf_type_list, sizeof(type_T *), 10);
-
 	if (argtypes.ga_len > 0)
 	{
 	    // When "varargs" is set the last name/type goes into uf_va_name
@@ -3608,7 +3624,7 @@
     void
 ex_function(exarg_T *eap)
 {
-    (void)def_function(eap, NULL);
+    (void)define_function(eap, NULL);
 }
 
 /*