2008-08-08 Marek Safar <marek.safar@gmail.com>
[mono.git] / mcs / mcs / delegate.cs
index c469e9835f8a28fa7b0d00361f0e645cf776fcff..e0065e2dd7cb548de7776aa8168e08827799693a 100644 (file)
@@ -364,7 +364,8 @@ namespace Mono.CSharp {
                        Parameters.VerifyClsCompliance ();
 
                        if (!AttributeTester.IsClsCompliant (ReturnType.Type)) {
-                               Report.Error (3002, Location, "Return type of `{0}' is not CLS-compliant", GetSignatureForError ());
+                               Report.Warning (3002, 1, Location, "Return type of `{0}' is not CLS-compliant",
+                                       GetSignatureForError ());
                        }
                        return true;
                }
@@ -446,18 +447,22 @@ namespace Mono.CSharp {
                        return (MethodInfo) mg.Methods[0];
                }
 
+               //
+               // 15.2 Delegate compatibility
+               //
                public static bool IsTypeCovariant (Expression a, Type b)
                {
-                       Type a_type = a.Type;
-                       if (a_type == b)
+                       //
+                       // For each value parameter (a parameter with no ref or out modifier), an 
+                       // identity conversion or implicit reference conversion exists from the
+                       // parameter type in D to the corresponding parameter type in M
+                       //
+                       if (a.Type == b)
                                return true;
 
                        if (RootContext.Version == LanguageVersion.ISO_1)
                                return false;
 
-                       if (!TypeManager.IsReferenceType (a_type))
-                               return false;
-
                        return Convert.ImplicitReferenceConversionExists (a, b);
                }
                
@@ -466,8 +471,7 @@ namespace Mono.CSharp {
                ///  Returns the method itself if okay and null if not.
                /// </summary>
                public static MethodBase VerifyMethod (Type container_type, Type delegate_type,
-                                                      MethodGroupExpr old_mg, MethodBase mb,
-                                                      Location loc)
+                                                      MethodGroupExpr old_mg, MethodBase mb)
                {
                        MethodInfo invoke_mb = GetInvokeMethod (container_type, delegate_type);
                        if (invoke_mb == null)
@@ -720,6 +724,8 @@ namespace Mono.CSharp {
                                return null;
 
                        delegate_method = (MethodInfo) method_group;
+                       Invocation.IsSpecialMethodInvocation (delegate_method, loc);
+
                        ExtensionMethodGroupExpr emg = method_group as ExtensionMethodGroupExpr;
                        if (emg != null) {
                                delegate_instance_expression = emg.ExtensionExpression;
@@ -808,13 +814,22 @@ namespace Mono.CSharp {
                                return null;
 
                        foreach (MethodInfo mi in mg.Methods){
-                               MethodBase mb = Delegate.VerifyMethod (mg.DeclaringType, target_type, mg, mi, Location.Null);
+                               MethodBase mb = Delegate.VerifyMethod (mg.DeclaringType, target_type, mg, mi);
                                if (mb != null)
                                        return mb;
                        }
                        return null;
                }
 
+               public override void MutateHoistedGenericType (AnonymousMethodStorey storey)
+               {
+                       if (delegate_instance_expression != null)
+                               delegate_instance_expression.MutateHoistedGenericType (storey);
+
+                       delegate_method = storey.MutateGenericMethod (delegate_method);
+                       constructor_method = storey.MutateConstructor (constructor_method);
+               }
+
                #region IErrorHandler Members
 
                public bool NoExactMatch (EmitContext ec, MethodBase method)
@@ -911,7 +926,7 @@ namespace Mono.CSharp {
                                        TypeManager.GetFullNameSignature (delegate_method));
                        }
 
-                       if (Invocation.IsMethodExcluded (delegate_method)) {
+                       if (Invocation.IsMethodExcluded (delegate_method, loc)) {
                                Report.SymbolRelatedToPreviousError (delegate_method);
                                Report.Error (1618, loc, "Cannot create delegate with `{0}' because it has a Conditional attribute",
                                        TypeManager.CSharpSignature (delegate_method));