patch 8.2.2272: Vim9: extend() can violate the type of a variable

Problem:    Vim9: extend() can violate the type of a variable.
Solution:   Add the type to the dictionary or list and check items against it.
            (closes #7593)
diff --git a/src/evalvars.c b/src/evalvars.c
index 94b857e..7fb190c 100644
--- a/src/evalvars.c
+++ b/src/evalvars.c
@@ -3147,9 +3147,9 @@
 	    di->di_flags &= ~DI_FLAGS_RELOAD;
 
 	    // A Vim9 script-local variable is also present in sn_all_vars and
-	    // sn_var_vals.
+	    // sn_var_vals.  It may set "type" from "tv".
 	    if (is_script_local && vim9script)
-		update_vim9_script_var(FALSE, di, tv, type);
+		update_vim9_script_var(FALSE, di, tv, &type);
 	}
 
 	// existing variable, need to clear the value
@@ -3237,9 +3237,9 @@
 	    di->di_flags |= DI_FLAGS_LOCK;
 
 	// A Vim9 script-local variable is also added to sn_all_vars and
-	// sn_var_vals.
+	// sn_var_vals. It may set "type" from "tv".
 	if (is_script_local && vim9script)
-	    update_vim9_script_var(TRUE, di, tv, type);
+	    update_vim9_script_var(TRUE, di, tv, &type);
     }
 
     if (copy || tv->v_type == VAR_NUMBER || tv->v_type == VAR_FLOAT)
@@ -3251,6 +3251,14 @@
 	init_tv(tv);
     }
 
+    if (vim9script && type != NULL)
+    {
+	if (type->tt_type == VAR_DICT && di->di_tv.vval.v_dict != NULL)
+	    di->di_tv.vval.v_dict->dv_type = alloc_type(type);
+	else if (type->tt_type == VAR_LIST && di->di_tv.vval.v_list != NULL)
+	    di->di_tv.vval.v_list->lv_type = alloc_type(type);
+    }
+
     // ":const var = value" locks the value
     // ":final var = value" locks "var"
     if (flags & ASSIGN_CONST)