Fix #72015.
[mono.git] / mcs / mcs / delegate.cs
index aad7186d603d3a0d77b751182616ddc30945193c..0eaaf114af890d6c0e16b0e527fdf47e1637490d 100644 (file)
@@ -79,9 +79,19 @@ namespace Mono.CSharp {
                        if (TypeBuilder != null)
                                return TypeBuilder;
 
+                       ec = new EmitContext (this, this, Location, null, null, ModFlags, false);
+
                        TypeAttributes attr = Modifiers.TypeAttr (ModFlags, IsTopLevel) |
                                TypeAttributes.Class | TypeAttributes.Sealed;
 
+                       if (TypeManager.multicast_delegate_type == null && !RootContext.StdLib) {
+                               TypeExpr expr = new TypeLookupExpression ("System.MulticastDelegate");
+                               TypeManager.multicast_delegate_type = expr.ResolveType (ec);
+                       }
+
+                       if (TypeManager.multicast_delegate_type == null)
+                               throw new InternalErrorException ("System.MulticastDelegate unresolved");
+
                        if (IsTopLevel) {
                                if (TypeManager.NamespaceClash (Name, Location))
                                        return null;
@@ -112,8 +122,9 @@ namespace Mono.CSharp {
                {
                        MethodAttributes mattr;
                        int i;
-                       EmitContext ec = new EmitContext (this, this, Location, null,
-                                                         null, ModFlags, false);
+
+                       if (ec == null)
+                               throw new InternalErrorException ("Define called before DefineType?");
 
                        // FIXME: POSSIBLY make this static, as it is always constant
                        //
@@ -359,8 +370,6 @@ namespace Mono.CSharp {
                public override void Emit ()
                {
                        if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (
-                                       Parent, this, Location, null, null, ModFlags, false);
                                Parameters.LabelParameters (ec, InvokeBuilder, Location);
                                OptAttributes.Emit (ec, this);
                        }
@@ -797,7 +806,7 @@ namespace Mono.CSharp {
                                delegate_instance_expression = ec.GetThis (loc);
                        
                        if (delegate_instance_expression != null && delegate_instance_expression.Type.IsValueType)
-                               delegate_instance_expression = new BoxedCast (mg.InstanceExpression);
+                               delegate_instance_expression = new BoxedCast (delegate_instance_expression);
                        
                        method_group = mg;
                        eclass = ExprClass.Value;
@@ -865,7 +874,7 @@ namespace Mono.CSharp {
                        
                        Expression e = a.Expr;
 
-                       if (e is AnonymousMethod)
+                       if (e is AnonymousMethod && RootContext.Version != LanguageVersion.ISO_1)
                                return ((AnonymousMethod) e).Compatible (ec, type, false);
 
                        MethodGroupExpr mg = e as MethodGroupExpr;
@@ -875,7 +884,7 @@ namespace Mono.CSharp {
                        Type e_type = e.Type;
 
                        if (!TypeManager.IsDelegateType (e_type)) {
-                               e.Error_UnexpectedKind ("method", loc);
+                               Report.Error (149, loc, "Method name expected");
                                return null;
                        }