Author: marek
Date: 2007-10-31 08:14:49 -0500 (Wed, 31 Oct 2007)
New Revision: 88552

Modified:
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/delegate.cs
Log:
2007-10-31  Marek Safar  <[EMAIL PROTECTED]>

        A fix for bugs #337712, #324490
        * delegate.cs: Delegate covariance and contravariance is not allowed for
        value types.
        


Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2007-10-31 11:16:23 UTC (rev 88551)
+++ trunk/mcs/mcs/ChangeLog     2007-10-31 13:14:49 UTC (rev 88552)
@@ -1,5 +1,11 @@
 2007-10-31  Marek Safar  <[EMAIL PROTECTED]>
 
+       A fix for bugs #337712, #324490
+       * delegate.cs: Delegate covariance and contravariance is not allowed for
+       value types.
+       
+2007-10-31  Marek Safar  <[EMAIL PROTECTED]>
+
        A fix for bug #337719 
        * cs-tokenizer.cs: Restore identifier buffer when parsing contextual
        `from' keyword.

Modified: trunk/mcs/mcs/delegate.cs
===================================================================
--- trunk/mcs/mcs/delegate.cs   2007-10-31 11:16:23 UTC (rev 88551)
+++ trunk/mcs/mcs/delegate.cs   2007-10-31 13:14:49 UTC (rev 88552)
@@ -445,6 +445,15 @@
 
                        return (MethodInfo) mg.Methods[0];
                }
+
+               public static bool IsTypeCovariant (Type a, Type b)
+               {
+                       if (a.IsValueType)
+                               return false;
+
+                       return Convert.ImplicitReferenceConversionCore (
+                               new EmptyExpression (a), b);
+               }
                
                /// <summary>
                ///  Verifies whether the method in question is compatible with 
the delegate
@@ -485,7 +494,7 @@
                                if (invoke_pd_type == pd_type)
                                        continue;
 
-                               if (!Convert.ImplicitReferenceConversionExists 
(new EmptyExpression (invoke_pd_type), pd_type))
+                               if (!IsTypeCovariant (invoke_pd_type, pd_type))
                                        return null;
 
                                if (RootContext.Version == 
LanguageVersion.ISO_1)
@@ -497,7 +506,7 @@
                        if (invoke_mb_retval == mb_retval)
                                return mb;
 
-                       if (!Convert.ImplicitReferenceConversionExists (new 
EmptyExpression (mb_retval), invoke_mb_retval))
+                       if (!IsTypeCovariant (mb_retval, invoke_mb_retval))
                                return null;
 
                        if (RootContext.Version == LanguageVersion.ISO_1) 
@@ -730,9 +739,9 @@
 
                        Type delegateType = method.ReturnType;
                        Type methodType = ((MethodInfo) 
found_method).ReturnType;
-                       if (delegateType != methodType &&
-                               !Convert.ImplicitReferenceConversionExists (new 
EmptyExpression (methodType), delegateType)) {
-                               Report.Error (407, loc, "`{0}' has the wrong 
return type to match the delegate `{1}'", method_desc, delegate_desc);
+                       if (delegateType != methodType && 
!Delegate.IsTypeCovariant (methodType, delegateType)) {
+                               Report.Error (407, loc, "The method `{0}' 
return type does not match delegate `{1}' return type",
+                                       method_desc, delegate_desc);
                        } else {
                                Report.Error (123, loc, "The method `{0}' 
parameters do not match delegate `{1}' parameters",
                                        TypeManager.CSharpSignature 
(found_method), delegate_desc);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to