Fix the build
[mono.git] / mcs / mcs / delegate.cs
index cec2ca907fedcbc76c61bbb646d3545e4a6f3e19..fa6a8e8ba46b0a1b0b6ca617912ccfe0e2164d71 100644 (file)
@@ -78,14 +78,6 @@ namespace Mono.CSharp {
                        if (TypeBuilder != null)
                                return TypeBuilder;
 
-#if GMCS_SOURCE
-                       if (IsGeneric) {
-                               foreach (TypeParameter type_param in TypeParameters)
-                                       if (!type_param.Resolve (this))
-                                               return null;
-                       }
-#endif
-                       
                        if (TypeManager.multicast_delegate_type == null && !RootContext.StdLib) {
                                Namespace system = RootNamespace.Global.GetNamespace ("System", true);
                                TypeExpr expr = system.Lookup (this, "MulticastDelegate", Location) as TypeExpr;
@@ -151,8 +143,20 @@ namespace Mono.CSharp {
                {
 #if GMCS_SOURCE
                        if (IsGeneric) {
-                               foreach (TypeParameter type_param in TypeParameters)
-                                       type_param.DefineType (this);
+                               foreach (TypeParameter type_param in TypeParameters) {
+                                       if (!type_param.Resolve (this))
+                                               return false;
+                               }
+
+                               foreach (TypeParameter type_param in TypeParameters) {
+                                       if (!type_param.DefineType (this))
+                                               return false;
+                               }
+
+                               foreach (TypeParameter type_param in TypeParameters) {
+                                       if (!type_param.CheckDependencies ())
+                                               return false;
+                               }
                        }
 #endif
 
@@ -413,35 +417,31 @@ namespace Mono.CSharp {
                                invoke_pd_type_mod &= ~Parameter.Modifier.PARAMS;
                                pd_type_mod &= ~Parameter.Modifier.PARAMS;
 
-                               if (invoke_pd_type == pd_type &&
-                                   invoke_pd_type_mod == pd_type_mod)
+                               if (invoke_pd_type_mod != pd_type_mod)
+                                       return null;
+
+                               if (invoke_pd_type == pd_type)
                                        continue;
-                               
-                               if (invoke_pd_type.IsSubclassOf (pd_type) && 
-                                   invoke_pd_type_mod == pd_type_mod)
-                                       if (RootContext.Version == LanguageVersion.ISO_1) {
-                                               Report.FeatureIsNotStandardized (loc, "contravariance");
-                                               return null;
-                                       } else
-                                               continue;
 
-                               return null;
+                               if (!Convert.ImplicitReferenceConversionExists (new EmptyExpression (invoke_pd_type), pd_type))
+                                       return null;
+
+                               if (RootContext.Version == LanguageVersion.ISO_1)
+                                       return null;
                        }
 
                        Type invoke_mb_retval = ((MethodInfo) invoke_mb).ReturnType;
                        Type mb_retval = ((MethodInfo) mb).ReturnType;
                        if (invoke_mb_retval == mb_retval)
                                return mb;
-                       
-                       if (mb_retval.IsSubclassOf (invoke_mb_retval))
-                               if (RootContext.Version == LanguageVersion.ISO_1) {
-                                       Report.FeatureIsNotStandardized (loc, "covariance");
-                                       return null;
-                               }
-                               else
-                                       return mb;
-                       
-                       return null;
+
+                       if (!Convert.ImplicitReferenceConversionExists (new EmptyExpression (mb_retval), invoke_mb_retval))
+                               return null;
+
+                       if (RootContext.Version == LanguageVersion.ISO_1) 
+                               return null;
+
+                       return mb;
                }
 
                // <summary>
@@ -617,7 +617,6 @@ namespace Mono.CSharp {
                public override string DocCommentHeader {
                        get { return "T:"; }
                }
-
        }
 
        //
@@ -653,16 +652,28 @@ namespace Mono.CSharp {
                        if (!mg.HasTypeArguments &&
                            !TypeManager.InferTypeArguments (param, ref found_method)) {
                                Report.Error (411, loc, "The type arguments for " +
-                                             "method `{0}' cannot be infered from " +
+                                             "method `{0}' cannot be inferred from " +
                                              "the usage. Try specifying the type " +
                                              "arguments explicitly.", method_desc);
                                return;
                        }
 #endif
-                       if (method.ReturnType != ((MethodInfo) found_method).ReturnType) {
+                       Report.SymbolRelatedToPreviousError (found_method);
+
+                       if (RootContext.Version == LanguageVersion.ISO_1) {
+                               Report.Error (410, loc, "The method `{0}' parameters and return type must be same as delegate `{1}' parameters and return type",
+                                       method_desc, delegate_desc);
+                               return;
+                       }
+
+                       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);
                        } else {
-                               Report.Error (123, loc, "Method `{0}' does not match delegate `{1}'", method_desc, delegate_desc);
+                               Report.Error (123, loc, "The method `{0}' parameters do not match delegate `{1}' parameters",
+                                       TypeManager.CSharpSignature (found_method), delegate_desc);
                        }
                }
                
@@ -813,9 +824,8 @@ namespace Mono.CSharp {
 
                public override Expression DoResolve (EmitContext ec)
                {
-                       if (Arguments == null || Arguments.Count != 1) {
-                               Report.Error (149, loc,
-                                             "Method name expected");
+                       if (Arguments == null) {
+                               Invocation.Error_WrongNumArguments (loc, GetSignatureForError (), 0);
                                return null;
                        }
 
@@ -829,12 +839,19 @@ namespace Mono.CSharp {
                        
                        Expression e = a.Expr;
 
-                       if (e is AnonymousMethod && RootContext.Version != LanguageVersion.ISO_1)
-                               return ((AnonymousMethod) e).Compatible (ec, type);
+                       if (e is AnonymousMethodExpression && RootContext.Version != LanguageVersion.ISO_1)
+                               return ((AnonymousMethodExpression) e).Compatible (ec, type);
 
                        MethodGroupExpr mg = e as MethodGroupExpr;
-                       if (mg != null)
+                       if (mg != null) {
+                               if (TypeManager.IsNullableType (mg.DeclaringType)) {
+                                       Report.Error (1728, loc, "Cannot use method `{0}' as delegate creation expression because it is member of Nullable type",
+                                               mg.GetSignatureForError ());
+                                       return null;
+                               }
+
                                return ResolveMethodGroupExpr (ec, mg);
+                       }
 
                        if (!TypeManager.IsDelegateType (e.Type)) {
                                Report.Error (149, loc, "Method name expected");
@@ -860,7 +877,7 @@ namespace Mono.CSharp {
                                
                        delegate_instance_expression = e;
                        delegate_method = method_group.Methods [0];
-                       
+
                        eclass = ExprClass.Value;
                        return this;
                }