patch 8.2.4231: Vim9: map() gives type error when type was not declared

Problem:    Vim9: map() gives type error when type was not declared.
Solution:   Only check the type when it was declared, like extend() does.
            (closes #9635)
diff --git a/src/evalfunc.c b/src/evalfunc.c
index 627ebb0..411d332 100644
--- a/src/evalfunc.c
+++ b/src/evalfunc.c
@@ -530,21 +530,30 @@
 
     if (type->tt_type == VAR_FUNC)
     {
-	if (type->tt_member != &t_any
-	    && type->tt_member != &t_unknown)
+	if (type->tt_member != &t_any && type->tt_member != &t_unknown)
 	{
 	    type_T *expected = NULL;
 
 	    if (context->arg_types[0].type_curr->tt_type == VAR_LIST
 		    || context->arg_types[0].type_curr->tt_type == VAR_DICT)
-		expected = context->arg_types[0].type_curr->tt_member;
+	    {
+		// Use the declared type, so that an error is given if a
+		// declared list changes type, but not if a constant list
+		// changes type.
+		if (context->arg_types[0].type_decl->tt_type == VAR_LIST
+			|| context->arg_types[0].type_decl->tt_type == VAR_DICT)
+		    expected = context->arg_types[0].type_decl->tt_member;
+		else
+		    expected = context->arg_types[0].type_curr->tt_member;
+	    }
 	    else if (context->arg_types[0].type_curr->tt_type == VAR_STRING)
 		expected = &t_string;
 	    else if (context->arg_types[0].type_curr->tt_type == VAR_BLOB)
 		expected = &t_number;
 	    if (expected != NULL)
 	    {
-		type_T t_func_exp = {VAR_FUNC, -1, 0, TTFLAG_STATIC, NULL, NULL};
+		type_T t_func_exp = {VAR_FUNC, -1, 0, TTFLAG_STATIC,
+								   NULL, NULL};
 
 		t_func_exp.tt_member = expected;
 		return check_arg_type(&t_func_exp, type, context);