patch 9.0.1974: vim9: using contra-variant type-checks

Problem:  vim9: using contra-variant type-checks (after v9.0.1959)
Solution: Use invariant type checking instead

closes: #13248

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
diff --git a/src/vim9class.c b/src/vim9class.c
index 790c2c3..885ac03 100644
--- a/src/vim9class.c
+++ b/src/vim9class.c
@@ -2561,7 +2561,7 @@
 {
     for (cctx_T *cctx = cctx_arg; cctx != NULL; cctx = cctx->ctx_outer)
 	if (cctx->ctx_ufunc != NULL
-			&& class_instance_of(cctx->ctx_ufunc->uf_class, cl, TRUE))
+			&& class_instance_of(cctx->ctx_ufunc->uf_class, cl))
 	    return TRUE;
     return FALSE;
 }
@@ -2871,39 +2871,29 @@
  * interfaces matches the class "other_cl".
  */
     int
-class_instance_of(class_T *cl, class_T *other_cl, int covariance_check)
+class_instance_of(class_T *cl, class_T *other_cl)
 {
     if (cl == other_cl)
 	return TRUE;
 
-    if (covariance_check)
+    // Recursively check the base classes.
+    for (; cl != NULL; cl = cl->class_extends)
     {
-	// Recursively check the base classes.
-	for (; cl != NULL; cl = cl->class_extends)
+	if (cl == other_cl)
+	    return TRUE;
+	// Check the implemented interfaces and the super interfaces
+	for (int i = cl->class_interface_count - 1; i >= 0; --i)
 	{
-	    if (cl == other_cl)
-		return TRUE;
-	    // Check the implemented interfaces and the super interfaces
-	    for (int i = cl->class_interface_count - 1; i >= 0; --i)
+	    class_T	*intf = cl->class_interfaces_cl[i];
+	    while (intf != NULL)
 	    {
-		class_T	*intf = cl->class_interfaces_cl[i];
-		while (intf != NULL)
-		{
-		    if (intf == other_cl)
-			return TRUE;
-		    // check the super interfaces
-		    intf = intf->class_extends;
-		}
+		if (intf == other_cl)
+		    return TRUE;
+		// check the super interfaces
+		intf = intf->class_extends;
 	    }
 	}
     }
-    else
-    {
-	// contra-variance
-	for (; other_cl != NULL; other_cl = other_cl->class_extends)
-	    if (cl == other_cl)
-		return TRUE;
-    }
 
     return FALSE;
 }
@@ -2938,7 +2928,7 @@
 	    }
 
 	    if (class_instance_of(object_tv->vval.v_object->obj_class,
-			li->li_tv.vval.v_class, TRUE) == TRUE)
+			li->li_tv.vval.v_class) == TRUE)
 	    {
 		rettv->vval.v_number = VVAL_TRUE;
 		return;
@@ -2947,9 +2937,8 @@
     }
     else if (classinfo_tv->v_type == VAR_CLASS)
     {
-	rettv->vval.v_number = class_instance_of(
-					object_tv->vval.v_object->obj_class,
-					classinfo_tv->vval.v_class, TRUE);
+	rettv->vval.v_number = class_instance_of(object_tv->vval.v_object->obj_class,
+		classinfo_tv->vval.v_class);
     }
 }