small cleanup
[mono.git] / mcs / gmcs / class.cs
index 09d627f8fa0156fadb9915dfd4ceb7d54eb3afdc..5a0d4f61e94ca79046468f3a7f8dc6efa30c5f2b 100644 (file)
@@ -470,7 +470,6 @@ namespace Mono.CSharp {
                Type GenericType;
                GenericTypeParameterBuilder[] gen_params;
 
-               public TypeContainer PartialContainer;
                ArrayList partial_parts;
 
                /// <remarks>
@@ -483,27 +482,26 @@ namespace Mono.CSharp {
                                      Attributes attrs, Kind kind)
                        : base (ns, parent, name, attrs)
                {
-                       // FIXME: Remove the second condition -- will require making RootContext.ToplevelTypes partial
-                       if (parent != null && parent != RootContext.ToplevelTypes && parent.NamespaceEntry != ns)
+                       if (parent != null && parent.NamespaceEntry != ns)
                                throw new InternalErrorException ("A nested type should be in the same NamespaceEntry as its enclosing class");
 
                        this.Kind = kind;
                        this.PartialContainer = this;
                }
 
-               public bool AddToMemberContainer (MemberCore symbol)
+               public bool AddMember (MemberCore symbol)
                {
                        return AddToContainer (symbol, symbol.MemberName.MethodName);
                }
 
-               protected virtual bool AddToTypeContainer (DeclSpace ds)
+               protected virtual bool AddMemberType (DeclSpace ds)
                {
                        return AddToContainer (ds, ds.Basename);
                }
 
                public void AddConstant (Const constant)
                {
-                       if (!AddToMemberContainer (constant))
+                       if (!AddMember (constant))
                                return;
 
                        if (constants == null)
@@ -514,7 +512,7 @@ namespace Mono.CSharp {
 
                public void AddEnum (Mono.CSharp.Enum e)
                {
-                       if (!AddToTypeContainer (e))
+                       if (!AddMemberType (e))
                                return;
 
                        if (enums == null)
@@ -522,36 +520,36 @@ namespace Mono.CSharp {
 
                        enums.Add (e);
                }
-               
-               public bool AddClassOrStruct (TypeContainer c)
-               {
-                       if (!AddToTypeContainer (c))
-                               return false;
 
-                       if (types == null)
-                               types = new ArrayList (2);
+               public TypeContainer AddTypeContainer (TypeContainer tc, bool is_interface)
+               {
+                       if (!AddMemberType (tc))
+                               return tc;
 
-                       types.Add (c);
-                       return true;
+                       if (is_interface) {
+                               if (interfaces == null)
+                                       interfaces = new MemberCoreArrayList ();
+                               interfaces.Add (tc);
+                       } else {
+                               if (types == null)
+                                       types = new ArrayList (2);
+                               types.Add (tc);
+                       }
+                       return tc;
                }
 
-               public virtual TypeContainer AddPartial (TypeContainer nextPart)
+               public virtual TypeContainer AddPartial (TypeContainer nextPart, bool is_interface)
                {
-                       return AddPartial (nextPart, nextPart.Basename);
+                       return AddPartial (nextPart, nextPart.Basename, is_interface);
                }
 
-               protected TypeContainer AddPartial (TypeContainer nextPart, string name)
+               protected TypeContainer AddPartial (TypeContainer nextPart, string name, bool is_interface)
                {
                        nextPart.ModFlags |= Modifiers.PARTIAL;
                        TypeContainer tc = defined_names [name] as TypeContainer;
 
-                       if (tc == null) {
-                               if (nextPart is Interface)
-                                       AddInterface (nextPart);
-                               else
-                                       AddClassOrStruct (nextPart);
-                               return nextPart;
-                       }
+                       if (tc == null)
+                               return AddTypeContainer (nextPart, is_interface);
 
                        if ((tc.ModFlags & Modifiers.PARTIAL) == 0) {
                                Report.SymbolRelatedToPreviousError (tc);
@@ -577,6 +575,21 @@ namespace Mono.CSharp {
                                return tc;
                        }
 
+                       if (tc.MemberName.IsGeneric) {
+                               TypeParameter[] tc_names = tc.TypeParameters;
+                               TypeParameterName[] part_names = nextPart.MemberName.TypeArguments.GetDeclarations ();
+
+                               for (int i = 0; i < tc_names.Length; ++i) {
+                                       if (tc_names[i].Name == part_names[i].Name)
+                                               continue;
+
+                                       Report.SymbolRelatedToPreviousError (part_names[i].Location, "");
+                                       Report.Error (264, tc.Location, "Partial declarations of `{0}' must have the same type parameter names in the same order",
+                                               tc.GetSignatureForError ());
+                                       return tc;
+                               }
+                       }
+
                        if (tc.partial_parts == null)
                                tc.partial_parts = new ArrayList (1);
 
@@ -595,7 +608,7 @@ namespace Mono.CSharp {
 
                public void AddDelegate (Delegate d)
                {
-                       if (!AddToTypeContainer (d))
+                       if (!AddMemberType (d))
                                return;
 
                        if (delegates == null)
@@ -606,7 +619,7 @@ namespace Mono.CSharp {
 
                public void AddMethod (Method method)
                {
-                       if (!AddToMemberContainer (method))
+                       if (!AddMember (method))
                                return;
 
                        if (methods == null)
@@ -625,7 +638,7 @@ namespace Mono.CSharp {
                //
                public void AppendMethod (Method method)
                {
-                       if (!AddToMemberContainer (method))
+                       if (!AddMember (method))
                                return;
 
                        if (methods == null)
@@ -672,22 +685,10 @@ namespace Mono.CSharp {
                                return "`{0}' is already defined. Rename this member or use different parameter types";
                        }
                }
-               
-               public bool AddInterface (TypeContainer iface)
-               {
-                       if (!AddToTypeContainer (iface))
-                               return false;
-
-                       if (interfaces == null)
-                               interfaces = new MemberCoreArrayList ();
-
-                       interfaces.Add (iface);
-                       return true;
-               }
 
                public void AddField (FieldMember field)
                {
-                       if (!AddToMemberContainer (field))
+                       if (!AddMember (field))
                                return;
 
                        if (fields == null)
@@ -715,8 +716,8 @@ namespace Mono.CSharp {
 
                public void AddProperty (Property prop)
                {
-                       if (!AddToMemberContainer (prop) || 
-                               !AddToMemberContainer (prop.Get) || !AddToMemberContainer (prop.Set))
+                       if (!AddMember (prop) || 
+                               !AddMember (prop.Get) || !AddMember (prop.Set))
                                return;
 
                        if (properties == null)
@@ -730,14 +731,14 @@ namespace Mono.CSharp {
 
                public void AddEvent (Event e)
                {
-                       if (!AddToMemberContainer (e))
+                       if (!AddMember (e))
                                return;
 
                        if (e is EventProperty) {
-                               if (!AddToMemberContainer (e.Add))
+                               if (!AddMember (e.Add))
                                        return;
 
-                               if (!AddToMemberContainer (e.Remove))
+                               if (!AddMember (e.Remove))
                                        return;
                        }
 
@@ -763,7 +764,7 @@ namespace Mono.CSharp {
 
                public void AddOperator (Operator op)
                {
-                       if (!AddToMemberContainer (op))
+                       if (!AddMember (op))
                                return;
 
                        if (operators == null)
@@ -976,6 +977,13 @@ namespace Mono.CSharp {
                        return base.GetClsCompliantAttributeValue ();
                }
 
+               public void AddBasesForPart (DeclSpace part, ArrayList bases)
+               {
+                       // FIXME: get rid of partial_parts and store lists of bases of each part here
+                       // assumed, not verified: 'part' is in 'partial_parts' 
+                       ((TypeContainer) part).Bases = bases;
+               }
+
                TypeExpr[] GetNormalBases (out TypeExpr base_class)
                {
                        base_class = null;
@@ -1204,7 +1212,7 @@ namespace Mono.CSharp {
                        // Let's do it as soon as possible, since code below can call DefineType() on classes
                        // that depend on us to be populated before they are.
                        //
-                       if (!(this is Iterator) && !(this is CompilerGeneratedClass))
+                       if (!(this is CompilerGeneratedClass))
                                RootContext.RegisterOrder (this); 
 
                        if (base_type != null) {
@@ -1252,10 +1260,6 @@ namespace Mono.CSharp {
                                TypeManager.RegisterBuilder (TypeBuilder, ifaces);
                        }
 
-                       if (this is Iterator && !ResolveType ()) {
-                               return false;
-                       }
-
                        return true;
                }
 
@@ -1315,6 +1319,18 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (instance_constructors != null) {
+                               foreach (Constructor c in instance_constructors) {
+                                       if (!c.ResolveMembers ())
+                                               return false;
+                               }
+                       }
+
+                       if (default_static_constructor != null) {
+                               if (!default_static_constructor.ResolveMembers ())
+                                       return false;
+                       }
+
                        if (operators != null) {
                                foreach (Operator o in operators) {
                                        if (!o.ResolveMembers ())
@@ -1369,22 +1385,21 @@ namespace Mono.CSharp {
 
                bool UpdateTypeParameterConstraints ()
                {
-                       bool ok = true;
-                       TypeParameter[] current_params = PartialContainer.CurrentTypeParameters;
-
                        if (constraints == null)
                                return true;
 
+                       TypeParameter[] current_params = PartialContainer.CurrentTypeParameters;
                        for (int i = 0; i < current_params.Length; i++) {
                                if (!current_params [i].UpdateConstraints (this, constraints [i])) {
-                                       Report.Error (265, Location, "Partial declarations of `{0}' have " +
-                                                     "inconsistent constraints for type parameter `{1}'.",
-                                                     MemberName.GetTypeName (), current_params [i].Name);
-                                       ok = false;
+                                       Report.SymbolRelatedToPreviousError (Location, "");
+                                       Report.Error (265, PartialContainer.Location,
+                                               "Partial declarations of `{0}' have inconsistent constraints for type parameter `{1}'",
+                                               PartialContainer.GetSignatureForError (), current_params [i].Name);
+                                       return false;
                                }
                        }
 
-                       return ok;
+                       return true;
                }
 
                public bool ResolveType ()
@@ -1534,6 +1549,9 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (!IsTopLevel && !Parent.PartialContainer.CheckRecursiveDefinition (this))
+                               return false;
+
                        InTransit = null;
                        return true;
                }
@@ -1577,7 +1595,7 @@ namespace Mono.CSharp {
                        }
 
                        if (!IsTopLevel) {
-                               MemberInfo conflict_symbol = Parent.MemberCache.FindMemberWithSameName (Basename, false, TypeBuilder);
+                               MemberInfo conflict_symbol = Parent.PartialContainer.FindBaseMemberWithSameName (Basename, false);
                                if (conflict_symbol == null) {
                                        if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0))
                                                Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
@@ -1646,7 +1664,7 @@ namespace Mono.CSharp {
 
                public MemberInfo FindBaseMemberWithSameName (string name, bool ignore_methods)
                {
-                       return BaseCache.FindMemberWithSameName (name, ignore_methods, null);
+                       return BaseCache == null ? null : BaseCache.FindMemberWithSameName (name, ignore_methods, null);
                }
 
                /// <summary>
@@ -1736,18 +1754,18 @@ namespace Mono.CSharp {
                
                // Indicated whether container has StructLayout attribute set Explicit
                public bool HasExplicitLayout {
-                       get {
-                               return (caching_flags & Flags.HasExplicitLayout) != 0;
-                       }
-                       set {
-                               caching_flags |= Flags.HasExplicitLayout;
-                       }
+                       get { return (caching_flags & Flags.HasExplicitLayout) != 0; }
+                       set { caching_flags |= Flags.HasExplicitLayout; }
                }
 
-               public override Type FindNestedType (string name)
+               //
+               // Return the nested type with name @name.  Ensures that the nested type
+               // is defined if necessary.  Do _not_ use this when you have a MemberCache handy.
+               //
+               public Type FindNestedType (string name)
                {
                        if (PartialContainer != this)
-                               return PartialContainer.FindNestedType (name);
+                               throw new InternalErrorException ("should not happen");
 
                        ArrayList [] lists = { types, enums, delegates, interfaces };
 
@@ -3290,7 +3308,7 @@ namespace Mono.CSharp {
                                return true;
 
                        // Is null for System.Object while compiling corlib and base interfaces
-                       if (ParentContainer.BaseCache == null) {
+                       if (Parent.PartialContainer.BaseCache == null) {
                                if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
                                        Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
                                }
@@ -3334,9 +3352,9 @@ namespace Mono.CSharp {
                                }
 
                                if (Name == "Equals" && Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type)
-                                       ParentContainer.Mark_HasEquals ();
+                                       Parent.PartialContainer.Mark_HasEquals ();
                                else if (Name == "GetHashCode" && Parameters.Empty)
-                                       ParentContainer.Mark_HasGetHashCode ();
+                                       Parent.PartialContainer.Mark_HasGetHashCode ();
 
                                if ((ModFlags & Modifiers.OVERRIDE) != 0) {
                                        ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (base_method);
@@ -3351,7 +3369,7 @@ namespace Mono.CSharp {
                                return true;
                        }
 
-                       MemberInfo conflict_symbol = ParentContainer.FindBaseMemberWithSameName (Name, !(this is Property));
+                       MemberInfo conflict_symbol = Parent.PartialContainer.FindBaseMemberWithSameName (Name, !(this is Property));
                        if ((ModFlags & Modifiers.OVERRIDE) != 0) {
                                if (conflict_symbol != null) {
                                        Report.SymbolRelatedToPreviousError (conflict_symbol);
@@ -3485,7 +3503,7 @@ namespace Mono.CSharp {
 
                public bool CheckAbstractAndExtern (bool has_block)
                {
-                       if (ParentContainer.Kind == Kind.Interface)
+                       if (Parent.PartialContainer.Kind == Kind.Interface)
                                return true;
 
                        if (has_block) {
@@ -3558,9 +3576,8 @@ namespace Mono.CSharp {
 
                        foreach (Type partype in parameters){
                                if (partype == TypeManager.void_type) {
-                                       Report.Error (
-                                               1547, Location, "Keyword 'void' cannot " +
-                                               "be used in this context");
+                                       // TODO: location is wrong
+                                       Expression.Error_VoidInvalidInTheContext (Location);
                                        return false;
                                }
 
@@ -3808,7 +3825,7 @@ namespace Mono.CSharp {
 
                                MethodBuilder = Parent.TypeBuilder.DefineMethod (method_name, flags);
 
-                               if (!GenericMethod.Define (MethodBuilder))
+                               if (!GenericMethod.Define (MethodBuilder, block))
                                        return false;
                        }
 
@@ -3822,7 +3839,7 @@ namespace Mono.CSharp {
 
                        if ((ModFlags & Modifiers.METHOD_YIELDS) != 0) {
                                iterator = Iterator.CreateIterator (
-                                       this, ParentContainer, GenericMethod, ModFlags);
+                                       this, Parent.PartialContainer, GenericMethod, ModFlags);
 
                                if (iterator == null)
                                        return false;
@@ -3852,7 +3869,7 @@ namespace Mono.CSharp {
                        MethodData = new MethodData (
                                this, ModFlags, flags, this, MethodBuilder, GenericMethod, base_method);
 
-                       if (!MethodData.Define (ParentContainer))
+                       if (!MethodData.Define (Parent.PartialContainer))
                                return false;
 
                        MethodBuilder = MethodData.MethodBuilder;
@@ -4120,27 +4137,27 @@ namespace Mono.CSharp {
                                CodeGen.FileName, TypeManager.CSharpSignature(b));
                }
 
-                bool IsEntryPoint (MethodBuilder b, Parameters pinfo)
-                {
-                        if (b.ReturnType != TypeManager.void_type &&
-                            b.ReturnType != TypeManager.int32_type)
-                                return false;
+               bool IsEntryPoint (Parameters pinfo)
+               {
+                       if (ReturnType != TypeManager.void_type &&
+                               ReturnType != TypeManager.int32_type)
+                               return false;
 
-                        if (pinfo.Count == 0)
-                                return true;
+                       if (pinfo.Count == 0)
+                               return true;
 
-                        if (pinfo.Count > 1)
-                                return false;
+                       if (pinfo.Count > 1)
+                               return false;
 
-                        Type t = pinfo.ParameterType(0);
-                        if (t.IsArray &&
-                            (t.GetArrayRank() == 1) &&
-                            (TypeManager.GetElementType(t) == TypeManager.string_type) &&
-                            (pinfo.ParameterModifier(0) == Parameter.Modifier.NONE))
-                                return true;
-                        else
-                                return false;
-                }
+                       Type t = pinfo.ParameterType (0);
+                       if (t.IsArray &&
+                               (t.GetArrayRank () == 1) &&
+                               (TypeManager.GetElementType (t) == TypeManager.string_type) &&
+                               (pinfo.ParameterModifier (0) == Parameter.Modifier.NONE))
+                               return true;
+                       else
+                               return false;
+               }
 
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                {
@@ -4184,7 +4201,7 @@ namespace Mono.CSharp {
 
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = ParentContainer.Methods;
+                       ArrayList ar = Parent.PartialContainer.Methods;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -4195,7 +4212,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = ParentContainer.Properties;
+                       ar = Parent.PartialContainer.Properties;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
                                        PropertyBase pb = (PropertyBase) ar [i];
@@ -4204,7 +4221,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = ParentContainer.Indexers;
+                       ar = Parent.PartialContainer.Indexers;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
                                        PropertyBase pb = (PropertyBase) ar [i];
@@ -4213,7 +4230,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = ParentContainer.Events;
+                       ar = Parent.PartialContainer.Events;
                        if (ar != null) {
                                for (int i = 0; i < ar.Count; ++i) {
                                        Event ev = (Event) ar [i];
@@ -4248,29 +4265,30 @@ namespace Mono.CSharp {
                        //
                        // This is used to track the Entry Point,
                        //
-                       if (Name == "Main" &&
-                               ((ModFlags & Modifiers.STATIC) != 0) && RootContext.NeedsEntryPoint && 
+                       if (RootContext.NeedsEntryPoint &&  ((ModFlags & Modifiers.STATIC) != 0) &&
+                               Name == "Main" &&
                                (RootContext.MainClass == null ||
                                RootContext.MainClass == Parent.TypeBuilder.FullName)){
-                               if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
-                                       IMethodData md = TypeManager.GetMethod (MethodBuilder);
-                                       md.SetMemberIsUsed ();
+                               if (IsEntryPoint (ParameterInfo)) {
 
                                        if (RootContext.EntryPoint == null) {
-                                               if (Parent.IsGeneric){
-                                                       Report.Error (-201, Location,
-                                                                     "Entry point can not be defined in a generic class");
-                                               }
+                                               if (Parent.IsGeneric || MemberName.IsGeneric) {
+                                                       Report.Warning (402, 4, Location, "`{0}': an entry point cannot be generic or in a generic type",
+                                                               GetSignatureForError ());
+                                               } else {
+                                                       IMethodData md = TypeManager.GetMethod (MethodBuilder);
+                                                       md.SetMemberIsUsed ();
 
-                                               RootContext.EntryPoint = MethodBuilder;
-                                               RootContext.EntryPointLocation = Location;
+                                                       RootContext.EntryPoint = MethodBuilder;
+                                                       RootContext.EntryPointLocation = Location;
+                                               }
                                        } else {
                                                Error_DuplicateEntryPoint (RootContext.EntryPoint, RootContext.EntryPointLocation);
                                                Error_DuplicateEntryPoint (MethodBuilder, Location);
                                        }
                                } else {
-                                       if (RootContext.WarningLevel >= 4)
-                                               Report.Warning (28, 4, Location, "`{0}' has the wrong signature to be an entry point", TypeManager.CSharpSignature(MethodBuilder));
+                                       Report.Warning (28, 4, Location, "`{0}' has the wrong signature to be an entry point",
+                                               GetSignatureForError ());
                                }
                        }
 
@@ -4297,7 +4315,7 @@ namespace Mono.CSharp {
 
                protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
-                       MethodInfo mi = (MethodInfo) ParentContainer.BaseCache.FindMemberToOverride (
+                       MethodInfo mi = (MethodInfo) Parent.PartialContainer.BaseCache.FindMemberToOverride (
                                Parent.TypeBuilder, Name, ParameterTypes, GenericMethod, false);
 
                        if (mi == null)
@@ -4316,7 +4334,7 @@ namespace Mono.CSharp {
                                return false;
 
                        if (ParameterInfo.Count > 0) {
-                               ArrayList al = (ArrayList)ParentContainer.MemberCache.Members [Name];
+                               ArrayList al = (ArrayList)Parent.PartialContainer.MemberCache.Members [Name];
                                if (al.Count > 1)
                                        MemberCache.VerifyClsParameterConflict (al, this, MethodBuilder);
                        }
@@ -4445,10 +4463,11 @@ namespace Mono.CSharp {
                }
        }
        
-       public class Constructor : MethodCore, IMethodData {
+       public class Constructor : MethodCore, IMethodData, IAnonymousHost {
                public ConstructorBuilder ConstructorBuilder;
                public ConstructorInitializer Initializer;
                ListDictionary declarative_security;
+               ArrayList anonymous_methods;
 
                // <summary>
                //   Modifiers allowed for a constructor.
@@ -4521,9 +4540,28 @@ namespace Mono.CSharp {
                        ConstructorBuilder.SetCustomAttribute (cb);
                }
 
+               public void AddAnonymousMethod (AnonymousMethodExpression anonymous)
+               {
+                       if (anonymous_methods == null)
+                               anonymous_methods = new ArrayList ();
+                       anonymous_methods.Add (anonymous);
+               }
+
+               public bool ResolveMembers ()
+               {
+                       if (anonymous_methods != null) {
+                               foreach (AnonymousMethodExpression ame in anonymous_methods) {
+                                       if (!ame.CreateAnonymousHelpers ())
+                                               return false;
+                               }
+                       }
+
+                       return true;
+               }
+
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = ParentContainer.InstanceConstructors;
+                       ArrayList ar = Parent.PartialContainer.InstanceConstructors;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -4556,7 +4594,7 @@ namespace Mono.CSharp {
                        if (!CheckForDuplications ())
                                return false;
 
-                       if (ParentContainer.Kind == Kind.Struct) {
+                       if (Parent.PartialContainer.Kind == Kind.Struct) {
                                if (ParameterTypes.Length == 0) {
                                        Report.Error (568, Location, 
                                                "Structs cannot contain explicit parameterless constructors");
@@ -4619,7 +4657,7 @@ namespace Mono.CSharp {
                        if ((ModFlags & Modifiers.UNSAFE) != 0)
                                ConstructorBuilder.InitLocals = false;
 
-                       if (ParentContainer.IsComImport) {
+                       if (Parent.PartialContainer.IsComImport) {
                                if (!IsDefault ()) {
                                        Report.Error (669, Location, "`{0}': A class with the ComImport attribute cannot have a user-defined constructor",
                                                Parent.GetSignatureForError ());
@@ -4646,8 +4684,8 @@ namespace Mono.CSharp {
                        if (block != null) {
                                // If this is a non-static `struct' constructor and doesn't have any
                                // initializer, it must initialize all of the struct's fields.
-                               if ((ParentContainer.Kind == Kind.Struct) &&
-                                       ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
+                               if ((Parent.PartialContainer.Kind == Kind.Struct) &&
+                                   ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
                                        block.AddThisVariable (Parent, Location);
 
                                if (!block.ResolveMeta (ec, ParameterInfo))
@@ -4655,7 +4693,7 @@ namespace Mono.CSharp {
                        }
 
                        if ((ModFlags & Modifiers.STATIC) == 0){
-                               if (ParentContainer.Kind == Kind.Class && Initializer == null)
+                               if (Parent.PartialContainer.Kind == Kind.Class && Initializer == null)
                                        Initializer = new GeneratedBaseInitializer (Location);
 
 
@@ -4678,7 +4716,7 @@ namespace Mono.CSharp {
                        //
                        // Classes can have base initializers and instance field initializers.
                        //
-                       if (ParentContainer.Kind == Kind.Class){
+                       if (Parent.PartialContainer.Kind == Kind.Class){
                                if ((ModFlags & Modifiers.STATIC) == 0){
 
                                        //
@@ -4686,7 +4724,7 @@ namespace Mono.CSharp {
                                        // do not emit field initializers, they are initialized in the other constructor
                                        //
                                        if (!(Initializer != null && Initializer is ConstructorThisInitializer))
-                                               ParentContainer.EmitFieldInitializers (ec);
+                                               Parent.PartialContainer.EmitFieldInitializers (ec);
                                }
                        }
 
@@ -4701,7 +4739,7 @@ namespace Mono.CSharp {
                        }
                        
                        if ((ModFlags & Modifiers.STATIC) != 0)
-                               ParentContainer.EmitFieldInitializers (ec);
+                               Parent.PartialContainer.EmitFieldInitializers (ec);
 
                        if (block != null)
                                ec.EmitResolvedTopBlock (block, unreachable);
@@ -4766,7 +4804,7 @@ namespace Mono.CSharp {
                        get {
                                CallingConventions cc = Parameters.CallingConvention;
 
-                               if (ParentContainer.Kind == Kind.Class)
+                               if (Parent.PartialContainer.Kind == Kind.Class)
                                        if ((ModFlags & Modifiers.STATIC) == 0)
                                                cc |= CallingConventions.HasThis;
 
@@ -4901,7 +4939,7 @@ namespace Mono.CSharp {
                        string name = method.MethodName.Basename;
                        string method_name = method.MethodName.FullName;
 
-                       TypeContainer container = ((TypeContainer) parent).PartialContainer;
+                       TypeContainer container = parent.PartialContainer;
 
                        PendingImplementation pending = container.PendingImplementations;
                        if (pending != null){
@@ -5150,20 +5188,6 @@ namespace Mono.CSharp {
                        
                        SourceMethod source = SourceMethod.Create (parent, MethodBuilder, method.Block);
 
-                       Report.Debug (64, "METHOD DATA EMIT", this, MethodBuilder,
-                                     method, method.Iterator, block);
-
-#if FIXME
-                       if (method.Iterator != null) {
-                               if (!method.Iterator.Resolve (ec))
-                                       throw new InternalErrorException ();
-                               // method.Iterator.EmitMethod (ec);
-                       }
-#endif
-
-                       Report.Debug (64, "METHOD DATA EMIT #1", this, MethodBuilder,
-                                     method, method.Iterator, block);
-
                        //
                        // Handle destructors specially
                        //
@@ -5265,10 +5289,6 @@ namespace Mono.CSharp {
                        set { SetMemberName (new MemberName (MemberName.Left, value, Location)); }
                }
 
-               public TypeContainer ParentContainer {
-                       get { return ((TypeContainer) Parent).PartialContainer; }
-               }
-
                //
                // The type of this property / indexer / event
                //
@@ -5321,7 +5341,7 @@ namespace Mono.CSharp {
 
                protected virtual bool CheckBase ()
                {
-                       if ((ModFlags & Modifiers.PROTECTED) != 0 && ParentContainer.Kind == Kind.Struct) {
+                       if ((ModFlags & Modifiers.PROTECTED) != 0 && Parent.PartialContainer.Kind == Kind.Struct) {
                                Report.Error (666, Location, "`{0}': new protected member declared in struct", GetSignatureForError ());
                                return false;
                        }
@@ -5351,7 +5371,7 @@ namespace Mono.CSharp {
                                        MethodAttributes.NewSlot |
                                        MethodAttributes.Virtual;
                        } else {
-                               if (!ParentContainer.MethodModifiersValid (this))
+                               if (!Parent.PartialContainer.MethodModifiersValid (this))
                                        return false;
 
                                flags = Modifiers.MethodAttr (ModFlags);
@@ -5370,7 +5390,7 @@ namespace Mono.CSharp {
                                        return false;
                                }
 
-                               if (!ParentContainer.VerifyImplements (this))
+                               if (!Parent.PartialContainer.VerifyImplements (this))
                                        return false;
                                
                                Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
@@ -5437,7 +5457,7 @@ namespace Mono.CSharp {
                                        return false;
                                }
                                
-                               if (!ParentContainer.VerifyImplements (this))
+                               if (!Parent.PartialContainer.VerifyImplements (this))
                                        return false;
                                
                                Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
@@ -5536,7 +5556,7 @@ namespace Mono.CSharp {
                        if (IsInterface)
                                return true;
 
-                       conflict_symbol = ParentContainer.FindBaseMemberWithSameName (Name, false);
+                       conflict_symbol = Parent.PartialContainer.FindBaseMemberWithSameName (Name, false);
                        if (conflict_symbol == null) {
                                if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
                                        Report.Warning (109, 4, Location, "The member `{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
@@ -5557,7 +5577,7 @@ namespace Mono.CSharp {
                        set {
                                if (value != null) {
                                        this.initializer = value;
-                                       ParentContainer.RegisterFieldForInitialization (this);
+                                       Parent.PartialContainer.RegisterFieldForInitialization (this);
                                }
                        }
                }
@@ -5645,7 +5665,7 @@ namespace Mono.CSharp {
                        {
                                status |= Status.HAS_OFFSET;
 
-                               if (!ParentContainer.HasExplicitLayout) {
+                               if (!Parent.PartialContainer.HasExplicitLayout) {
                                        Report.Error (636, Location, "The FieldOffset attribute can only be placed on members of types marked with the StructLayout(LayoutKind.Explicit)");
                                        return;
                                }
@@ -5670,7 +5690,8 @@ namespace Mono.CSharp {
                                return false;
                        
                        if (MemberType == TypeManager.void_type) {
-                               Report.Error (1547, Location, "Keyword 'void' cannot be used in this context");
+                               // TODO: wrong location
+                               Expression.Error_VoidInvalidInTheContext (Location);
                                return false;
                        }
 
@@ -5697,7 +5718,7 @@ namespace Mono.CSharp {
                                OptAttributes.Emit ();
                        }
 
-                       if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0 && ParentContainer.HasExplicitLayout) {
+                       if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0 && Parent.PartialContainer.HasExplicitLayout) {
                                Report.Error (625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.", GetSignatureForError ());
                        }
 
@@ -5783,7 +5804,7 @@ namespace Mono.CSharp {
                                Report.Warning (-23, 1, Location, "Only private or internal fixed sized buffers are supported by .NET 1.x");
 #endif
 
-                       if (ParentContainer.Kind != Kind.Struct) {
+                       if (Parent.PartialContainer.Kind != Kind.Struct) {
                                Report.Error (1642, Location, "`{0}': Fixed size buffer fields may only be members of structs",
                                        GetSignatureForError ());
                                return false;
@@ -5953,7 +5974,7 @@ namespace Mono.CSharp {
 
                        FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
 
-                       if (ParentContainer.Kind == Kind.Struct && 
+                       if (Parent.PartialContainer.Kind == Kind.Struct && 
                            ((fa & FieldAttributes.Static) == 0) &&
                            MemberType == Parent.TypeBuilder &&
                            !TypeManager.IsBuiltinType (MemberType)){
@@ -6430,7 +6451,7 @@ namespace Mono.CSharp {
                                if (!method.CheckAbstractAndExtern (block != null))
                                        return null;
 
-                               TypeContainer container = ((TypeContainer) parent).PartialContainer;
+                               TypeContainer container = parent.PartialContainer;
 
                                //
                                // Check for custom access modifier
@@ -6586,7 +6607,7 @@ namespace Mono.CSharp {
 
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = ParentContainer.Indexers;
+                       ArrayList ar = Parent.PartialContainer.Indexers;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -6597,7 +6618,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = ParentContainer.Properties;
+                       ar = Parent.PartialContainer.Properties;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
@@ -6614,7 +6635,7 @@ namespace Mono.CSharp {
                // TODO: rename to Resolve......
                protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
-                       PropertyInfo base_property = ParentContainer.BaseCache.FindMemberToOverride (
+                       PropertyInfo base_property = Parent.PartialContainer.BaseCache.FindMemberToOverride (
                                Parent.TypeBuilder, Name, ParameterTypes, null, true) as PropertyInfo;
 
                        if (base_property == null)
@@ -7473,8 +7494,8 @@ namespace Mono.CSharp {
                                        ShortName = base_IndexerName;
                        }
 
-                       if (!ParentContainer.AddToMemberContainer (this) ||
-                               !ParentContainer.AddToMemberContainer (Get) || !ParentContainer.AddToMemberContainer (Set))
+                       if (!Parent.PartialContainer.AddMember (this) ||
+                               !Parent.PartialContainer.AddMember (Get) || !Parent.PartialContainer.AddMember (Set))
                                return false;
 
                        if (!CheckBase ())
@@ -7623,7 +7644,7 @@ namespace Mono.CSharp {
                
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = ParentContainer.Operators;
+                       ArrayList ar = Parent.PartialContainer.Operators;
                        if (ar != null) {
                                int arLen = ar.Count;
 
@@ -7634,7 +7655,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       ar = ParentContainer.Methods;
+                       ar = Parent.PartialContainer.Methods;
                        if (ar != null) {
                                int arLen = ar.Count;