2005-05-31 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / mcs / class.cs
index f6faa4bdffe23b9387764cb3c64fdcd3709edb46..34b1a3b0b5d8686ac91b12e49fb8da6a32d7826c 100644 (file)
@@ -2,7 +2,7 @@
 // class.cs: Class and Struct handlers
 //
 // Authors: Miguel de Icaza (miguel@gnu.org)
-//          Martin Baulig (martin@gnome.org)
+//          Martin Baulig (martin@ximian.com)
 //          Marek Safar (marek.safar@seznam.cz)
 //
 // Licensed under the terms of the GNU GPL
@@ -64,6 +64,15 @@ namespace Mono.CSharp {
        /// </summary>
        public abstract class TypeContainer : DeclSpace, IMemberContainer {
 
+               protected class CircularDepException: Exception
+               {
+                       public TypeContainer Container;
+                       public CircularDepException (TypeContainer tc)
+                       {
+                               Container = tc;
+                       }
+               }
+
                public class MemberCoreArrayList: ArrayList
                {
                        /// <summary>
@@ -278,7 +287,11 @@ namespace Mono.CSharp {
                                // Register all the operators we care about.
                                foreach (Operator op in this){
                                        int reg = 0;
-                                       
+
+                                       // Skip erroneous code.
+                                       if (op.OperatorMethod == null)
+                                               continue;
+
                                        switch (op.OperatorType){
                                        case Operator.OpType.Equality:
                                                reg = 1;
@@ -444,7 +457,7 @@ namespace Mono.CSharp {
                // from classes from the arraylist `type_bases' 
                //
                string     base_class_name;
-               TypeExpr parent_type;
+               TypeExpr base_type;
 
                ArrayList type_bases;
 
@@ -455,16 +468,22 @@ namespace Mono.CSharp {
                protected Type [] ifaces;
                protected Type ptype;
 
-               // The parent member cache and our member cache
-               MemberCache parent_cache;
+               // The base member cache and our member cache
+               MemberCache base_cache;
                MemberCache member_cache;
 
                public const string DefaultIndexerName = "Item";
+
+               // This is used to catch recursive definitions in declarations.
+               protected bool InTransit;
                
                public TypeContainer (NamespaceEntry ns, TypeContainer parent, MemberName name,
                                      Attributes attrs, Kind kind, Location l)
                        : base (ns, parent, name, attrs, l)
                {
+                       if (parent != null && parent != RootContext.Tree.Types && parent.NamespaceEntry != ns)
+                               throw new InternalErrorException ("A nested type should be in the same NamespaceEntry as its enclosing class");
+
                        this.Kind = kind;
 
                        types = new ArrayList ();
@@ -472,19 +491,20 @@ namespace Mono.CSharp {
                        base_class_name = null;
                }
 
-               public bool AddToMemberContainer (MemberCore symbol, bool is_method)
+               public bool AddToMemberContainer (MemberCore symbol)
                {
-                       return AddToContainer (symbol, is_method, String.Concat (Name, '.', symbol.Name), symbol.Name);
+                       return AddToContainer (symbol, symbol.Name);
                }
 
                bool AddToTypeContainer (DeclSpace ds)
                {
-                       return AddToContainer (ds, false, ds.Name, ds.Basename);
+                       // Parent == null ==> this == RootContext.Tree.Types
+                       return AddToContainer (ds, (Parent == null) ? ds.Name : ds.Basename);
                }
 
                public void AddConstant (Const constant)
                {
-                       if (!AddToMemberContainer (constant, false))
+                       if (!AddToMemberContainer (constant))
                                return;
 
                        if (constants == null)
@@ -525,13 +545,13 @@ namespace Mono.CSharp {
 
                public void AddMethod (Method method)
                {
-                       if (!AddToMemberContainer (method, true))
+                       if (!AddToMemberContainer (method))
                                return;
 
                        if (methods == null)
                                methods = new MethodArrayList (this);
                        
-                       if (method.Name.IndexOf ('.') != -1)
+                       if (method.MemberName.Left != null)
                                methods.Insert (0, method);
                        else 
                                methods.Add (method);
@@ -588,9 +608,9 @@ namespace Mono.CSharp {
                        interfaces.Add (iface);
                }
 
-               public void AddField (Field field)
+               public void AddField (FieldMember field)
                {
-                       if (!AddToMemberContainer (field, false))
+                       if (!AddToMemberContainer (field))
                                return;
 
                        if (fields == null)
@@ -598,19 +618,8 @@ namespace Mono.CSharp {
                        
                        fields.Add (field);
 
-                       if (field.HasInitializer){
-                               if ((field.ModFlags & Modifiers.STATIC) != 0){
-                                       if (initialized_static_fields == null)
-                                               initialized_static_fields = new ArrayList ();
-                       
-                                       initialized_static_fields.Add (field);
-                               } else {
-                                       if (initialized_fields == null)
-                                               initialized_fields = new ArrayList ();
-                                                       
-                                       initialized_fields.Add (field);
-                               }
-                       }
+                       if (field.HasInitializer)
+                               RegisterFieldForInitialization (field);
                        
                        if ((field.ModFlags & Modifiers.STATIC) == 0)
                                have_nonstatic_fields = true;
@@ -618,14 +627,14 @@ namespace Mono.CSharp {
 
                public void AddProperty (Property prop)
                {
-                       if (!AddToMemberContainer (prop, false) || 
-                               !AddToMemberContainer (prop.Get, true) || !AddToMemberContainer (prop.Set, true))
+                       if (!AddToMemberContainer (prop) || 
+                               !AddToMemberContainer (prop.Get) || !AddToMemberContainer (prop.Set))
                                return;
 
                        if (properties == null)
                                properties = new MemberCoreArrayList ();
 
-                       if (prop.Name.IndexOf ('.') != -1)
+                       if (prop.MemberName.Left != null)
                                properties.Insert (0, prop);
                        else
                                properties.Add (prop);
@@ -633,14 +642,14 @@ namespace Mono.CSharp {
 
                public void AddEvent (Event e)
                {
-                       if (!AddToMemberContainer (e, false))
+                       if (!AddToMemberContainer (e))
                                return;
 
                        if (e is EventProperty) {
-                               if (!AddToMemberContainer (e.Add, true))
+                               if (!AddToMemberContainer (e.Add))
                                        return;
 
-                               if (!AddToMemberContainer (e.Remove, true))
+                               if (!AddToMemberContainer (e.Remove))
                                        return;
                        }
 
@@ -667,7 +676,7 @@ namespace Mono.CSharp {
 
                public void AddOperator (Operator op)
                {
-                       if (!AddToMemberContainer (op, true))
+                       if (!AddToMemberContainer (op))
                                return;
 
                        if (operators == null)
@@ -713,7 +722,16 @@ namespace Mono.CSharp {
 
                public override AttributeTargets AttributeTargets {
                        get {
-                               throw new NotSupportedException ();
+                               switch (Kind) {
+                               case Kind.Class:
+                                       return AttributeTargets.Class;
+                               case Kind.Struct:
+                                       return AttributeTargets.Struct;
+                               case Kind.Interface:
+                                       return AttributeTargets.Interface;
+                               default:
+                                       throw new NotSupportedException ();
+                               }
                        }
                }
 
@@ -817,9 +835,9 @@ namespace Mono.CSharp {
                        }
                }
 
-               public virtual TypeAttributes TypeAttr {
+               protected override TypeAttributes TypeAttr {
                        get {
-                               return Modifiers.TypeAttr (ModFlags, this);
+                               return Modifiers.TypeAttr (ModFlags, this) | base.TypeAttr;
                        }
                }
 
@@ -829,10 +847,25 @@ namespace Mono.CSharp {
                        }
                }
 
+               public virtual void RegisterFieldForInitialization (FieldMember field)
+               {
+                       if ((field.ModFlags & Modifiers.STATIC) != 0){
+                               if (initialized_static_fields == null)
+                                       initialized_static_fields = new ArrayList ();
+
+                               initialized_static_fields.Add (field);
+                       } else {
+                               if (initialized_fields == null)
+                                       initialized_fields = new ArrayList ();
+
+                               initialized_fields.Add (field);
+                       }
+               }
+
                //
                // Emits the instance field initializers
                //
-               public bool EmitFieldInitializers (EmitContext ec)
+               public virtual bool EmitFieldInitializers (EmitContext ec)
                {
                        ArrayList fields;
                        Expression instance_expr;
@@ -848,13 +881,13 @@ namespace Mono.CSharp {
                        if (fields == null)
                                return true;
 
-                       foreach (Field f in fields){
+                       foreach (FieldMember f in fields){
                                Expression e = f.GetInitializerExpression (ec);
                                if (e == null)
                                        return false;
 
                                Location l = f.Location;
-                               FieldExpr fe = new FieldExpr (f.FieldBuilder, l);
+                               FieldExpr fe = new FieldExpr (f.FieldBuilder, l, true);
                                fe.InstanceExpression = instance_expr;
                                ExpressionStatement a = new Assign (fe, e, l);
 
@@ -862,6 +895,12 @@ namespace Mono.CSharp {
                                if (a == null)
                                        return false;
 
+                               Constant c = e as Constant;
+                               if (c != null) {
+                                       if (c.IsDefaultValue)
+                                               continue;
+                               }
+
                                a.EmitStatement (ec);
                        }
 
@@ -885,7 +924,12 @@ namespace Mono.CSharp {
                        else if ((ModFlags & Modifiers.ABSTRACT) != 0)
                                mods = Modifiers.PROTECTED;
 
-                       c = new Constructor (this, Basename, mods, Parameters.EmptyReadOnlyParameters,
+                       TypeContainer constructor_parent = this;
+                       if (Parts != null)
+                               constructor_parent = (TypeContainer) Parts [0];
+
+                       c = new Constructor (constructor_parent, Basename, mods,
+                                            Parameters.EmptyReadOnlyParameters,
                                             new ConstructorBaseInitializer (
                                                     null, Parameters.EmptyReadOnlyParameters,
                                                     Location),
@@ -903,42 +947,39 @@ namespace Mono.CSharp {
                /// </remarks>
                public PendingImplementation Pending;
 
-               public abstract void Register ();
-
                public abstract PendingImplementation GetPendingImplementations ();
 
-               TypeExpr[] GetPartialBases (out TypeExpr parent, out bool error)
+               TypeExpr[] GetPartialBases (out TypeExpr base_class)
                {
                        ArrayList ifaces = new ArrayList ();
 
-                       parent = null;
-                       Location parent_loc = Location.Null;
+                       base_class = null;
+                       Location base_loc = Location.Null;
 
                        foreach (ClassPart part in parts) {
-                               TypeExpr new_parent;
+                               TypeExpr new_base_class;
                                TypeExpr[] new_ifaces;
 
-                               new_ifaces = part.GetClassBases (out new_parent, out error);
-                               if (error)
+                               new_ifaces = part.GetClassBases (out new_base_class);
+                               if (new_ifaces == null && base_type != null)
                                        return null;
 
-                               if ((parent != null) && (new_parent != null) &&
-                                   !parent.Equals (new_parent)) {
+                               if ((base_class != null) && (new_base_class != null) &&
+                                   !base_class.Equals (new_base_class)) {
                                        Report.Error (263, part.Location,
                                                      "Partial declarations of `{0}' must " +
                                                      "not specify different base classes",
                                                      Name);
 
-                                       if (!Location.IsNull (parent_loc))
-                                               Report.LocationOfPreviousError (parent_loc);
+                                       if (!Location.IsNull (base_loc))
+                                               Report.LocationOfPreviousError (base_loc);
 
-                                       error = true;
                                        return null;
                                }
 
-                               if ((parent == null) && (new_parent != null)) {
-                                       parent = new_parent;
-                                       parent_loc = part.Location;
+                               if ((base_class == null) && (new_base_class != null)) {
+                                       base_class = new_base_class;
+                                       base_loc = part.Location;
                                }
 
                                if (new_ifaces == null)
@@ -958,53 +999,45 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       error = false;
-
                        TypeExpr[] retval = new TypeExpr [ifaces.Count];
                        ifaces.CopyTo (retval, 0);
                        return retval;
                }
 
-               TypeExpr[] GetNormalBases (out TypeExpr parent, out bool error)
+               TypeExpr[] GetNormalBases (out TypeExpr base_class)
                {
-                       parent = null;
+                       base_class = null;
 
                        int count = Bases.Count;
-                       int start, i, j;
+                       int start = 0, i, j;
 
                        if (Kind == Kind.Class){
-                               TypeExpr name = ResolveTypeExpr (
+                               TypeExpr name = ResolveBaseTypeExpr (
                                        (Expression) Bases [0], false, Location);
 
                                if (name == null){
-                                       error = true;
                                        return null;
                                }
 
-                               if (name.IsClass){
-                                       parent = name;
+                               if (!name.IsInterface) {
+                                       // base_class could be a class, struct, enum, delegate.
+                                       // This is validated in GetClassBases.
+                                       base_class = name;
                                        start = 1;
-                               } else {
-                                       start = 0;
                                }
-                       } else {
-                               start = 0;
                        }
 
                        TypeExpr [] ifaces = new TypeExpr [count-start];
                        
                        for (i = start, j = 0; i < count; i++, j++){
-                               Expression name = (Expression) Bases [i];
-                               TypeExpr resolved = ResolveTypeExpr (name, false, Location);
+                               TypeExpr resolved = ResolveBaseTypeExpr ((Expression) Bases [i], false, Location);
                                if (resolved == null) {
-                                       error = true;
                                        return null;
                                }
                                
                                ifaces [j] = resolved;
                        }
 
-                       error = false;
                        return ifaces;
                }
 
@@ -1015,33 +1048,36 @@ namespace Mono.CSharp {
                ///   The return value is an array (might be null) of
                ///   interfaces implemented (as Types).
                ///   
-               ///   The @parent argument is set to the parent object or null
+               ///   The @base_class argument is set to the base object or null
                ///   if this is `System.Object'. 
                /// </summary>
-               TypeExpr [] GetClassBases (out TypeExpr parent, out bool error)
+               TypeExpr [] GetClassBases (out TypeExpr base_class)
                {
                        int i;
 
-                       error = false;
-
                        TypeExpr[] ifaces;
 
                        if (parts != null)
-                               ifaces = GetPartialBases (out parent, out error);
+                               ifaces = GetPartialBases (out base_class);
                        else if (Bases == null){
-                               parent = null;
+                               base_class = null;
                                return null;
                        } else
-                               ifaces = GetNormalBases (out parent, out error);
+                               ifaces = GetNormalBases (out base_class);
 
-                       if (error)
+                       if (ifaces == null)
                                return null;
 
-                       if ((parent != null) && (Kind == Kind.Class)){
-                               if (parent.IsSealed){
-                                       error = true;
-                                       Report.SymbolRelatedToPreviousError (parent.Type);
-                                       if (parent.Type.IsAbstract) {
+                       if ((base_class != null) && (Kind == Kind.Class)){
+
+                               if (base_class.Type.IsArray || base_class.Type.IsPointer) {
+                                       Report.Error (1521, base_class.Location, "Invalid base type");
+                                       return null;
+                               }
+
+                               if (base_class.IsSealed){
+                                       Report.SymbolRelatedToPreviousError (base_class.Type);
+                                       if (base_class.Type.IsAbstract) {
                                                Report.Error (709, Location, "'{0}': Cannot derive from static class", GetSignatureForError ());
                                        } else {
                                                Report.Error (509, Location, "'{0}': Cannot derive from sealed class", GetSignatureForError ());
@@ -1049,23 +1085,22 @@ namespace Mono.CSharp {
                                        return null;
                                }
 
-                               if (!parent.CanInheritFrom ()){
+                               if (!base_class.CanInheritFrom ()){
                                        Report.Error (644, Location,
                                                      "`{0}' cannot inherit from special class `{1}'",
-                                                     Name, parent.Name);
-                                       error = true;
+                                                     Name, base_class.Name);
                                        return null;
                                }
 
-                               if (!parent.AsAccessible (this, ModFlags)) {
-                                       Report.SymbolRelatedToPreviousError (parent.Type);
+                               if (!base_class.AsAccessible (this, ModFlags)) {
+                                       Report.SymbolRelatedToPreviousError (base_class.Type);
                                        Report.Error (60, Location, "Inconsistent accessibility: base class '{0}' is less accessible than class '{1}'", 
-                                               TypeManager.CSharpName (parent.Type), GetSignatureForError ());
+                                               TypeManager.CSharpName (base_class.Type), GetSignatureForError ());
                                }
                        }
 
-                       if (parent != null)
-                               base_class_name = parent.Name;
+                       if (base_class != null)
+                               base_class_name = base_class.Name;
 
                        if (ifaces == null)
                                return null;
@@ -1075,18 +1110,12 @@ namespace Mono.CSharp {
                        for (i = 0; i < count; i++) {
                                TypeExpr iface = (TypeExpr) ifaces [i];
 
-                               if ((Kind != Kind.Class) && !iface.IsInterface){
-                                       string what = Kind == Kind.Struct ?
-                                               "Struct" : "Interface";
-
-                                       Report.Error (527, Location,
-                                                     "In {0} `{1}', type `{2}' is not "+
-                                                     "an interface", what, Name, iface.Name);
-                                       error = true;
-                                       return null;
-                               }
-                               if (iface.IsClass) {
-                                       if (parent != null)
+                               if (!iface.IsInterface) {
+                                       if (Kind != Kind.Class) {
+                                               // TODO: location of symbol related ....
+                                               Error_TypeInListIsNotInterface (Location, iface.FullName);
+                                       }
+                                       else if (base_class != null)
                                                Report.Error (1721, Location,
                                                              "In Class `{0}', `{1}' is not an interface, and a base class has already been defined",
                                                              Name, iface.Name);
@@ -1095,7 +1124,6 @@ namespace Mono.CSharp {
                                                              "In Class `{0}', `{1}' is not " +
                                                              "an interface, a base class must be listed first", Name, iface.Name);
                                        }
-                                       error = true;
                                        return null;
                                }
 
@@ -1104,25 +1132,28 @@ namespace Mono.CSharp {
                                                Report.Error (528, Location,
                                                              "`{0}' is already listed in " +
                                                              "interface list", iface.Name);
-                                               error = true;
                                                return null;
                                        }
                                }
 
                                if ((Kind == Kind.Interface) &&
-                                   !iface.AsAccessible (Parent, ModFlags))
+                                   !iface.AsAccessible (Parent, ModFlags)) {
                                        Report.Error (61, Location,
                                                      "Inconsistent accessibility: base " +
                                                      "interface `{0}' is less accessible " +
                                                      "than interface `{1}'", iface.Name,
                                                      Name);
+                                       return null;
+                               }
                        }
-
                        return ifaces;
                }
 
-               bool error = false;
-               
+               protected void Error_TypeInListIsNotInterface (Location loc, string type)
+               {
+                       Report.Error (527, loc, "'{0}': type in interface list is not an interface", type);
+               }
+
                //
                // Defines the type in the appropriate ModuleBuilder or TypeBuilder.
                //
@@ -1130,40 +1161,31 @@ namespace Mono.CSharp {
                {
                        if (TypeBuilder != null)
                                return TypeBuilder;
-
-                       if (error)
-                               return null;
-
-                       if (InTransit) {
-                               Report.Error (146, Location, "Class definition is circular: `{0}'", Name);
-                               error = true;
-                               return null;
-                       }
                        
                        InTransit = true;
 
-                       ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
-
-                       TypeExpr[] iface_exprs = GetClassBases (out parent_type, out error);
-                       if (error)
+                       TypeExpr[] iface_exprs = GetClassBases (out base_type);
+                       if (iface_exprs == null && base_type != null) {
+                               InTransit = false;
                                return null;
+                       }
 
-                       if (parent_type == null) {
+                       if (base_type == null) {
                                if (Kind == Kind.Class){
                                        if (RootContext.StdLib)
-                                               parent_type = TypeManager.system_object_expr;
+                                               base_type = TypeManager.system_object_expr;
                                        else if (Name != "System.Object")
-                                               parent_type = TypeManager.system_object_expr;
+                                               base_type = TypeManager.system_object_expr;
                                } else if (Kind == Kind.Struct) {
                                        //
                                        // If we are compiling our runtime,
                                        // and we are defining ValueType, then our
-                                       // parent is `System.Object'.
+                                       // base is `System.Object'.
                                        //
                                        if (!RootContext.StdLib && Name == "System.ValueType")
-                                               parent_type = TypeManager.system_object_expr;
+                                               base_type = TypeManager.system_object_expr;
                                        else
-                                               parent_type = TypeManager.system_valuetype_expr;
+                                               base_type = TypeManager.system_valuetype_expr;
                                }
                        }
 
@@ -1172,10 +1194,12 @@ namespace Mono.CSharp {
 
                        TypeAttributes type_attributes = TypeAttr;
 
-                       if (parent_type != null) {
-                               ptype = parent_type.ResolveType (ec);
+                       if (base_type != null) {
+                               // FIXME: I think this should be ...ResolveType (Parent.EmitContext).
+                               //        However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
+                               ptype = base_type.ResolveType (TypeResolveEmitContext);
                                if (ptype == null) {
-                                       error = true;
+                                       InTransit = false;
                                        return null;
                                }
                        }
@@ -1183,7 +1207,7 @@ namespace Mono.CSharp {
                        try {
                                if (IsTopLevel){
                                        if (TypeManager.NamespaceClash (Name, Location)) {
-                                               error = true;
+                                               InTransit = false;
                                                return null;
                                        }
                                
@@ -1192,9 +1216,11 @@ namespace Mono.CSharp {
                                                Name, type_attributes, ptype, null);
                                
                                } else {
-                                       TypeBuilder builder = Parent.DefineType ();
-                                       if (builder == null)
+                                       TypeBuilder builder = Parent.TypeBuilder;
+                                       if (builder == null) {
+                                               InTransit = false;
                                                return null;
+                                       }
                                
                                        TypeBuilder = builder.DefineNestedType (
                                                Basename, type_attributes, ptype, null);
@@ -1202,26 +1228,32 @@ namespace Mono.CSharp {
                        }
                        catch (ArgumentException) {
                                Report.RuntimeMissingSupport (Location, "static classes");
+                               InTransit = false;
                                return null;
                        }
-                               
-                       //
-                       // Structs with no fields need to have at least one byte.
-                       // The right thing would be to set the PackingSize in a DefineType
-                       // but there are no functions that allow interfaces *and* the size to
-                       // be specified.
-                       //
 
-                       if ((Kind == Kind.Struct) && !have_nonstatic_fields){
-                               TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
-                                                        FieldAttributes.Private);
+                       if (Parts != null) {
+                               ec = null;
+                               foreach (ClassPart part in Parts) {
+                                       part.TypeBuilder = TypeBuilder;
+                                       part.ptype = ptype;
+                                       part.ec = new EmitContext (part, Mono.CSharp.Location.Null, null, null, ModFlags);
+                                       part.ec.ContainerType = TypeBuilder;
+                               }
+                       }
+                       else {
+                               ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
+                               ec.ContainerType = TypeBuilder;
                        }
 
                        // add interfaces that were not added at type creation
                        if (iface_exprs != null) {
-                               ifaces = TypeManager.ExpandInterfaces (ec, iface_exprs);
+                               // FIXME: I think this should be ...ExpandInterfaces (Parent.EmitContext, ...).
+                               //        However, if Parent == RootContext.Tree.Types, its NamespaceEntry will be null.
+                               TypeResolveEmitContext.ContainerType = TypeBuilder;
+                               ifaces = TypeManager.ExpandInterfaces (TypeResolveEmitContext, iface_exprs);
                                if (ifaces == null) {
-                                       error = true;
+                                       InTransit = false;
                                        return null;
                                }
 
@@ -1231,24 +1263,17 @@ namespace Mono.CSharp {
                                TypeManager.RegisterBuilder (TypeBuilder, ifaces);
                        }
 
-                       //
-                       // Finish the setup for the EmitContext
-                       //
-                       ec.ContainerType = TypeBuilder;
-
                        TypeManager.AddUserType (Name, TypeBuilder, this);
 
-                       if ((parent_type != null) && parent_type.IsAttribute) {
-                               RootContext.RegisterAttribute (this);
-                       } else if (!(this is Iterator))
+                       if (!(this is Iterator))
                                RootContext.RegisterOrder (this); 
 
+                       InTransit = false;
+
                        if (!DefineNestedTypes ()) {
-                               error = true;
                                return null;
                        }
 
-                       InTransit = false;
                        return TypeBuilder;
                }
 
@@ -1278,14 +1303,6 @@ namespace Mono.CSharp {
                                                return false;
                        }
 
-                       if (Parts != null) {
-                               foreach (ClassPart part in Parts) {
-                                       part.TypeBuilder = TypeBuilder;
-                                       part.ptype = ptype;
-                                       part.ec = new EmitContext (part, Mono.CSharp.Location.Null, null, null, ModFlags);
-                               }
-                       }
-
                        return true;
                }
 
@@ -1310,43 +1327,26 @@ namespace Mono.CSharp {
 
                bool DoDefineMembers ()
                {
-                       //
-                       // We need to be able to use the member cache while we are checking/defining
-                       //
-                       if (TypeBuilder.BaseType != null)
-                               parent_cache = TypeManager.LookupMemberCache (TypeBuilder.BaseType);
-
-                       if (TypeBuilder.IsInterface)
-                               parent_cache = TypeManager.LookupParentInterfacesCache (TypeBuilder);
-
                        if (IsTopLevel) {
                                if ((ModFlags & Modifiers.NEW) != 0)
                                        Error_KeywordNotAllowed (Location);
                        } else {
-                               // HACK: missing implemenation
-                               // This is not fully functional. Better way how to handle this is to have recursive definition of containers
-                               // instead of flat as we have now.
-                               // Now we are not able to check inner attribute class because its parent had not been defined.
-                               // TODO: remove this if
-                               if (Parent.MemberCache != null) {
-                                       MemberInfo conflict_symbol = Parent.MemberCache.FindMemberWithSameName (Basename, false, TypeBuilder);
-                                       if (conflict_symbol == null) {
-                                               if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0))
-                                                       Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
-                                       } else {
-                                               if ((ModFlags & Modifiers.NEW) == 0) {
-                                                       Report.SymbolRelatedToPreviousError (conflict_symbol);
-                                                       Report.Warning (108, Location, "The keyword new is required on '{0}' because it hides inherited member", GetSignatureForError ());
-                                               }
+                               MemberInfo conflict_symbol = Parent.MemberCache.FindMemberWithSameName (Basename, false, TypeBuilder);
+                               if (conflict_symbol == null) {
+                                       if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0))
+                                               Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
+                               } else {
+                                       if ((ModFlags & Modifiers.NEW) == 0) {
+                                               Report.SymbolRelatedToPreviousError (conflict_symbol);
+                                               Report.Warning (108, Location, "The keyword new is required on '{0}' because it hides inherited member", GetSignatureForError ());
                                        }
-                               }
+                               }
                        }
 
                        DefineContainerMembers (constants);
                        DefineContainerMembers (fields);
 
-                       if ((Kind == Kind.Class) && !(this is ClassPart) && !(this is StaticClass)){
+                       if ((Kind == Kind.Class) && !(this is ClassPart)){
                                if ((instance_constructors == null) &&
                                    !(this is StaticClass)) {
                                        if (default_constructor == null)
@@ -1451,9 +1451,9 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public MemberInfo FindMemberWithSameName (string name, bool ignore_methods)
+               public MemberInfo FindBaseMemberWithSameName (string name, bool ignore_methods)
                {
-                       return ParentCache.FindMemberWithSameName (name, ignore_methods, null);
+                       return BaseCache.FindMemberWithSameName (name, ignore_methods, null);
                }
 
                /// <summary>
@@ -1547,6 +1547,62 @@ namespace Mono.CSharp {
                                return false;
                        }
                }
+
+               public override Type FindNestedType (string name)
+               {
+                       ArrayList [] lists = { types, enums, delegates, interfaces };
+
+                       for (int j = 0; j < lists.Length; ++j) {
+                               ArrayList list = lists [j];
+                               if (list == null)
+                                       continue;
+                               
+                               int len = list.Count;
+                               for (int i = 0; i < len; ++i) {
+                                       DeclSpace ds = (DeclSpace) list [i];
+                                       if (ds.Basename == name) {
+                                               ds.DefineType ();
+                                               return ds.TypeBuilder;
+                                       }
+                               }
+                       }
+
+                       return null;
+               }
+
+               private void FindMembers_NestedTypes (int modflags,
+                                                     BindingFlags bf, MemberFilter filter, object criteria,
+                                                     ref ArrayList members)
+               {
+                       ArrayList [] lists = { types, enums, delegates, interfaces };
+
+                       for (int j = 0; j < lists.Length; ++j) {
+                               ArrayList list = lists [j];
+                               if (list == null)
+                                       continue;
+                       
+                               int len = list.Count;
+                               for (int i = 0; i < len; i++) {
+                                       DeclSpace ds = (DeclSpace) list [i];
+                                       
+                                       if ((ds.ModFlags & modflags) == 0)
+                                               continue;
+                                       
+                                       TypeBuilder tb = ds.TypeBuilder;
+                                       if (tb == null) {
+                                               if (!(criteria is string) || ds.Basename.Equals (criteria))
+                                                       tb = ds.DefineType ();
+                                       }
+                                       
+                                       if (tb != null && (filter (tb, criteria) == true)) {
+                                               if (members == null)
+                                                       members = new ArrayList ();
+                                               
+                                               members.Add (tb);
+                                       }
+                               }
+                       }
+               }
                
                /// <summary>
                ///   This method returns the members of this type just like Type.FindMembers would
@@ -1604,7 +1660,7 @@ namespace Mono.CSharp {
                                if (fields != null) {
                                        int len = fields.Count;
                                        for (int i = 0; i < len; i++) {
-                                               Field f = (Field) fields [i];
+                                               FieldMember f = (FieldMember) fields [i];
                                                
                                                if ((f.ModFlags & modflags) == 0)
                                                        continue;
@@ -1632,6 +1688,10 @@ namespace Mono.CSharp {
                                                        continue;
 
                                                FieldBuilder fb = con.FieldBuilder;
+                                               if (fb == null) {
+                                                       if (con.Define ())
+                                                               fb = con.FieldBuilder;
+                                               }
                                                if (fb != null && filter (fb, criteria) == true) {
                                                        if (members == null)
                                                                members = new ArrayList ();
@@ -1809,79 +1869,8 @@ namespace Mono.CSharp {
                                }
                        }
                        
-                       if ((mt & MemberTypes.NestedType) != 0) {
-                               if (types != null) {
-                                       int len = types.Count;
-                                       for (int i = 0; i < len; i++) {
-                                               TypeContainer t = (TypeContainer) types [i];
-                                               
-                                               if ((t.ModFlags & modflags) == 0)
-                                                       continue;
-
-                                               TypeBuilder tb = t.TypeBuilder;
-                                               if (tb != null && (filter (tb, criteria) == true)) {
-                                                       if (members == null)
-                                                               members = new ArrayList ();
-                                                       
-                                                       members.Add (tb);
-                                               }
-                                       }
-                               }
-
-                               if (enums != null) {
-                                       int len = enums.Count;
-                                       for (int i = 0; i < len; i++) {
-                                               Enum en = (Enum) enums [i];
-                                               
-                                               if ((en.ModFlags & modflags) == 0)
-                                                       continue;
-
-                                               TypeBuilder tb = en.TypeBuilder;
-                                               if (tb != null && (filter (tb, criteria) == true)) {
-                                                       if (members == null)
-                                                               members = new ArrayList ();
-                                                       
-                                                       members.Add (tb);
-                                               }
-                                       }
-                               }
-                               
-                               if (delegates != null) {
-                                       int len = delegates.Count;
-                                       for (int i = 0; i < len; i++) {
-                                               Delegate d = (Delegate) delegates [i];
-                                               
-                                               if ((d.ModFlags & modflags) == 0)
-                                                       continue;
-
-                                               TypeBuilder tb = d.TypeBuilder;
-                                               if (tb != null && (filter (tb, criteria) == true)) {
-                                                       if (members == null)
-                                                               members = new ArrayList ();
-                                                       
-                                                       members.Add (tb);
-                                               }
-                                       }
-                               }
-
-                               if (interfaces != null) {
-                                       int len = interfaces.Count;
-                                       for (int i = 0; i < len; i++) {
-                                               TypeContainer iface = (TypeContainer) interfaces [i];
-                                               
-                                               if ((iface.ModFlags & modflags) == 0)
-                                                       continue;
-
-                                               TypeBuilder tb = iface.TypeBuilder;
-                                               if (tb != null && (filter (tb, criteria) == true)) {
-                                                       if (members == null)
-                                                               members = new ArrayList ();
-                                                       
-                                                       members.Add (tb);
-                                               }
-                                       }
-                               }
-                       }
+                       if ((mt & MemberTypes.NestedType) != 0)
+                               FindMembers_NestedTypes (modflags, bf, filter, criteria, ref members);
 
                        if ((mt & MemberTypes.Constructor) != 0){
                                if (((bf & BindingFlags.Instance) != 0) && (instance_constructors != null)){
@@ -1913,7 +1902,7 @@ namespace Mono.CSharp {
                        }
 
                        //
-                       // Lookup members in parent if requested.
+                       // Lookup members in base if requested.
                        //
                        if ((bf & BindingFlags.DeclaredOnly) == 0) {
                                if (TypeBuilder.BaseType != null) {
@@ -1985,18 +1974,37 @@ namespace Mono.CSharp {
                        return;
                }
 
-               protected virtual void VerifyMembers (EmitContext ec)
+               void CheckMemberUsage (MemberCoreArrayList al, string member_type)
+               {
+                       if (al == null)
+                               return;
+
+                       foreach (MemberCore mc in al) {
+                               if ((mc.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
+                                       continue;
+
+                               if (!mc.IsUsed) {
+                                       Report.Warning (169, mc.Location, "The private {0} '{1}' is never used", member_type, mc.GetSignatureForError ());
+                               }
+                       }
+               }
+
+               public virtual void VerifyMembers ()
                {
                        //
                        // Check for internal or private fields that were never assigned
                        //
                        if (RootContext.WarningLevel >= 3) {
+                               CheckMemberUsage (properties, "property");
+                               CheckMemberUsage (methods, "method");
+                               CheckMemberUsage (constants, "constant");
+
                                if (fields != null){
-                                       foreach (Field f in fields) {
+                                       foreach (FieldMember f in fields) {
                                                if ((f.ModFlags & Modifiers.Accessibility) != Modifiers.PRIVATE)
                                                        continue;
                                                
-                                               if ((f.status & Field.Status.USED) == 0){
+                                               if (!f.IsUsed){
                                                        Report.Warning (169, f.Location, "The private field '{0}' is never used", f.GetSignatureForError ());
                                                        continue;
                                                }
@@ -2025,6 +2033,27 @@ namespace Mono.CSharp {
                        if (OptAttributes != null)
                                OptAttributes.Emit (ec, this);
                                
+                       //
+                       // Structs with no fields need to have at least one byte.
+                       // The right thing would be to set the PackingSize in a DefineType
+                       // but there are no functions that allow interfaces *and* the size to
+                       // be specified.
+                       //
+
+                       if ((Kind == Kind.Struct) && !have_nonstatic_fields){
+                               FieldBuilder fb = TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
+                                                                          FieldAttributes.Private);
+
+                               if (HasExplicitLayout){
+                                       object [] ctor_args = new object [1];
+                                       ctor_args [0] = 0;
+                               
+                                       CustomAttributeBuilder cba = new CustomAttributeBuilder (
+                                               TypeManager.field_offset_attribute_ctor, ctor_args);
+                                       fb.SetCustomAttribute (cba);
+                               }
+                       }
+
                        Emit ();
 
                        if (instance_constructors != null) {
@@ -2069,7 +2098,7 @@ namespace Mono.CSharp {
                        }
                        
                        if (fields != null)
-                               foreach (Field f in fields)
+                               foreach (FieldMember f in fields)
                                        f.Emit ();
 
                        if (events != null){
@@ -2098,8 +2127,6 @@ namespace Mono.CSharp {
                                if (Pending.VerifyPendingMethods ())
                                        return;
 
-                       VerifyMembers (ec);
-
                        if (iterators != null)
                                foreach (Iterator iterator in iterators)
                                        iterator.EmitType ();
@@ -2170,7 +2197,7 @@ namespace Mono.CSharp {
                        type_bases = null;
                        OptAttributes = null;
                        ifaces = null;
-                       parent_cache = null;
+                       base_cache = null;
                        member_cache = null;
                }
 
@@ -2184,36 +2211,34 @@ namespace Mono.CSharp {
                // Performs the validation on a Method's modifiers (properties have
                // the same properties).
                //
-               public bool MethodModifiersValid (int flags, string n, Location loc)
+               public bool MethodModifiersValid (MemberCore mc)
                {
                        const int vao = (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE);
                        const int va = (Modifiers.VIRTUAL | Modifiers.ABSTRACT);
                        const int nv = (Modifiers.NEW | Modifiers.VIRTUAL);
                        bool ok = true;
+                       int flags = mc.ModFlags;
                        
                        //
                        // At most one of static, virtual or override
                        //
                        if ((flags & Modifiers.STATIC) != 0){
                                if ((flags & vao) != 0){
-                                       Report.Error (
-                                               112, loc, "static method " + MakeName (n) + "can not be marked " +
-                                               "as virtual, abstract or override");
+                                       Report.Error (112, mc.Location, "static method '{0}' can not be marked as virtual, abstract or override",
+                                               GetSignatureForError ());
                                        ok = false;
                                }
                        }
 
                        if (Kind == Kind.Struct){
                                if ((flags & va) != 0){
-                                       Modifiers.Error_InvalidModifier (loc, "virtual or abstract");
+                                       Modifiers.Error_InvalidModifier (mc.Location, "virtual or abstract");
                                        ok = false;
                                }
                        }
 
                        if ((flags & Modifiers.OVERRIDE) != 0 && (flags & nv) != 0){
-                               Report.Error (
-                                       113, loc, MakeName (n) +
-                                       " marked as override cannot be marked as new or virtual");
+                               Report.Error (113, mc.Location, "'{0}' marked as override cannot be marked as new or virtual", mc.GetSignatureForError ());
                                ok = false;
                        }
 
@@ -2224,39 +2249,36 @@ namespace Mono.CSharp {
                        if ((flags & Modifiers.ABSTRACT) != 0){
                                if ((flags & Modifiers.EXTERN) != 0){
                                        Report.Error (
-                                               180, loc, MakeName (n) + " can not be both abstract and extern");
+                                               180, mc.Location, "'{0}' can not be both abstract and extern", mc.GetSignatureForError ());
+                                       ok = false;
+                               }
+
+                               if ((flags & Modifiers.SEALED) != 0) {
+                                       Report.Error (502, mc.Location, "'{0}' cannot be both abstract and sealed", mc.GetSignatureForError ());
                                        ok = false;
                                }
 
                                if ((flags & Modifiers.VIRTUAL) != 0){
-                                       Report.Error (
-                                               503, loc, MakeName (n) + " can not be both abstract and virtual");
+                                       Report.Error (503, mc.Location, "'{0}' can not be both abstract and virtual", mc.GetSignatureForError ());
                                        ok = false;
                                }
 
                                if ((ModFlags & Modifiers.ABSTRACT) == 0){
-                                       Report.Error (
-                                               513, loc, MakeName (n) +
-                                               " is abstract but its container class is not");
+                                       Report.Error (513, mc.Location, "'{0}' is abstract but its container class is not", mc.GetSignatureForError ());
                                        ok = false;
-
                                }
                        }
 
                        if ((flags & Modifiers.PRIVATE) != 0){
                                if ((flags & vao) != 0){
-                                       Report.Error (
-                                               621, loc, MakeName (n) +
-                                               " virtual or abstract members can not be private");
+                                       Report.Error (621, mc.Location, "'{0}' virtual or abstract members can not be private", mc.GetSignatureForError ());
                                        ok = false;
                                }
                        }
 
                        if ((flags & Modifiers.SEALED) != 0){
                                if ((flags & Modifiers.OVERRIDE) == 0){
-                                       Report.Error (
-                                               238, loc, MakeName (n) +
-                                               " cannot be sealed because it is not an override");
+                                       Report.Error (238, mc.Location, "'{0}' cannot be sealed because it is not an override", mc.GetSignatureForError ());
                                        ok = false;
                                }
                        }
@@ -2285,6 +2307,11 @@ namespace Mono.CSharp {
                        if (base_type != null && !AttributeTester.IsClsCompliant (base_type)) {
                                Report.Error (3009, Location, "'{0}': base type '{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (base_type));
                        }
+
+                       if (!Parent.IsClsCompliaceRequired (ds)) {
+                               Report.Error (3018, Location, "'{0}' cannot be marked as CLS-Compliant because it is a member of non CLS-Compliant type '{1}'", 
+                                       GetSignatureForError (), Parent.GetSignatureForError ());
+                       }
                        return true;
                }
 
@@ -2294,9 +2321,9 @@ namespace Mono.CSharp {
                /// </summary>
                void VerifyClsName ()
                {
-                       Hashtable parent_members = parent_cache == null ? 
+                       Hashtable base_members = base_cache == null ? 
                                new Hashtable () :
-                               parent_cache.GetPublicMembers ();
+                               base_cache.GetPublicMembers ();
                        Hashtable this_members = new Hashtable ();
 
                        foreach (DictionaryEntry entry in defined_names) {
@@ -2308,7 +2335,7 @@ namespace Mono.CSharp {
                                string basename = name.Substring (name.LastIndexOf ('.') + 1);
 
                                string lcase = basename.ToLower (System.Globalization.CultureInfo.InvariantCulture);
-                               object found = parent_members [lcase];
+                               object found = base_members [lcase];
                                if (found == null) {
                                        found = this_members [lcase];
                                        if (found == null) {
@@ -2419,9 +2446,15 @@ namespace Mono.CSharp {
                        get { return "T:"; }
                }
 
-               public virtual MemberCache ParentCache {
+               public virtual MemberCache BaseCache {
                        get {
-                               return parent_cache;
+                               if (base_cache != null)
+                                       return base_cache;
+                               if (TypeBuilder.BaseType != null)
+                                       base_cache = TypeManager.LookupMemberCache (TypeBuilder.BaseType);
+                               if (TypeBuilder.IsInterface)
+                                       base_cache = TypeManager.LookupBaseInterfacesCache (TypeBuilder);
+                               return base_cache;
                        }
                }
        }
@@ -2438,8 +2471,7 @@ namespace Mono.CSharp {
                                                Location loc)
                {
                        PartialContainer pc;
-                       string full_name = member_name.GetName (true);
-                       DeclSpace ds = (DeclSpace) RootContext.Tree.Decls [full_name];
+                       DeclSpace ds = RootContext.Tree.GetDecl (member_name);
                        if (ds != null) {
                                pc = ds as PartialContainer;
 
@@ -2473,10 +2505,19 @@ namespace Mono.CSharp {
                                return pc;
                        }
 
-                       pc = new PartialContainer (ns, parent, member_name, mod_flags, kind, loc);
-                       RootContext.Tree.RecordDecl (full_name, pc);
-                       parent.AddType (pc);
-                       pc.Register ();
+                       if (parent is ClassPart)
+                               parent = ((ClassPart) parent).PartialContainer;
+
+                       pc = new PartialContainer (ns.NS, parent, member_name, mod_flags, kind, loc);
+                       RootContext.Tree.RecordDecl (member_name, pc);
+
+                       if (kind == Kind.Interface)
+                               parent.AddInterface (pc);
+                       else if (kind == Kind.Class || kind == Kind.Struct)
+                               parent.AddClassOrStruct (pc);
+                       else
+                               throw new InvalidOperationException ();
+
                        return pc;
                }
 
@@ -2488,19 +2529,19 @@ namespace Mono.CSharp {
                        if (pc == null) {
                                // An error occured; create a dummy container, but don't
                                // register it.
-                               pc = new PartialContainer (ns, parent, name, mod, kind, loc);
+                               pc = new PartialContainer (ns.NS, parent, name, mod, kind, loc);
                        }
 
-                       ClassPart part = new ClassPart (ns, pc, mod, attrs, kind, loc);
+                       ClassPart part = new ClassPart (ns, pc, parent, mod, attrs, kind, loc);
                        pc.AddPart (part);
                        return part;
                }
 
-               protected PartialContainer (NamespaceEntry ns, TypeContainer parent,
+               protected PartialContainer (Namespace ns, TypeContainer parent,
                                            MemberName name, int mod, Kind kind, Location l)
-                       : base (ns, parent, name, null, kind, l)
+                       : base (null, parent, name, null, kind, l)
                {
-                       this.Namespace = ns.NS;
+                       this.Namespace = ns;
 
                        switch (kind) {
                        case Kind.Class:
@@ -2532,30 +2573,12 @@ namespace Mono.CSharp {
                        this.OriginalModFlags = mod;
                }
 
-               public override void Register ()
-               {
-                       if (Kind == Kind.Interface)
-                               Parent.AddInterface (this);
-                       else if (Kind == Kind.Class || Kind == Kind.Struct)
-                               Parent.AddClassOrStruct (this);
-                       else
-                               throw new InvalidOperationException ();
-               }
-
                public override PendingImplementation GetPendingImplementations ()
                {
                        return PendingImplementation.GetPendingImplementations (this);
                }
 
-               public ClassPart AddPart (NamespaceEntry ns, int mod, Attributes attrs,
-                                         Location l)
-               {
-                       ClassPart part = new ClassPart (ns, this, mod, attrs, Kind, l);
-                       AddPart (part);
-                       return part;
-               }
-
-               public override TypeAttributes TypeAttr {
+               protected override TypeAttributes TypeAttr {
                        get {
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
@@ -2566,25 +2589,20 @@ namespace Mono.CSharp {
                public readonly PartialContainer PartialContainer;
                public readonly bool IsPartial;
 
-               public ClassPart (NamespaceEntry ns, PartialContainer parent,
+               public ClassPart (NamespaceEntry ns, PartialContainer pc, TypeContainer parent,
                                  int mod, Attributes attrs, Kind kind, Location l)
-                       : base (ns, parent.Parent, parent.MemberName, attrs, kind, l)
+                       : base (ns, parent, pc.MemberName, attrs, kind, l)
                {
-                       this.PartialContainer = parent;
+                       this.PartialContainer = pc;
                        this.IsPartial = true;
 
                        int accmods;
-                       if (parent.Parent == null)
+                       if (parent == null || parent == RootContext.Tree.Types)
                                accmods = Modifiers.INTERNAL;
                        else
                                accmods = Modifiers.PRIVATE;
 
-                       this.ModFlags = Modifiers.Check (
-                               parent.AllowedModifiers, mod, accmods, l);
-               }
-
-               public override void Register ()
-               {
+                       this.ModFlags = Modifiers.Check (pc.AllowedModifiers, mod, accmods, l);
                }
 
                public override PendingImplementation GetPendingImplementations ()
@@ -2599,15 +2617,31 @@ namespace Mono.CSharp {
                                interface_type, full, name, loc);
                }
 
-               public override MemberCache ParentCache {
+
+               public override void RegisterFieldForInitialization (FieldMember field)
+               {
+                       PartialContainer.RegisterFieldForInitialization (field);
+               }
+
+               public override bool EmitFieldInitializers (EmitContext ec)
+               {
+                       return PartialContainer.EmitFieldInitializers (ec);
+               }
+
+               public override Type FindNestedType (string name)
+               {
+                       return PartialContainer.FindNestedType (name);
+               }
+
+               public override MemberCache BaseCache {
                        get {
-                               return PartialContainer.ParentCache;
+                               return PartialContainer.BaseCache;
                        }
                }
        }
 
        public abstract class ClassOrStruct : TypeContainer {
-               bool hasExplicitLayout = false;
+               bool has_explicit_layout = false;
                ListDictionary declarative_security;
 
                public ClassOrStruct (NamespaceEntry ns, TypeContainer parent,
@@ -2624,13 +2658,13 @@ namespace Mono.CSharp {
 
                public override bool HasExplicitLayout {
                        get {
-                               return hasExplicitLayout;
+                               return has_explicit_layout;
                        }
                }
 
-               protected override void VerifyMembers (EmitContext ec)
+               public override void VerifyMembers ()
                {
-                       base.VerifyMembers (ec);
+                       base.VerifyMembers ();
 
                        if ((events != null) && (RootContext.WarningLevel >= 3)) {
                                foreach (Event e in events){
@@ -2650,9 +2684,8 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (a.Type == TypeManager.struct_layout_attribute_type
-                           && (LayoutKind) a.GetPositionalValue (0) == LayoutKind.Explicit)
-                               hasExplicitLayout = true;
+                       if (a.Type == TypeManager.struct_layout_attribute_type && a.GetLayoutKindValue () == LayoutKind.Explicit)
+                               has_explicit_layout = true;
 
                        base.ApplyAttributeBuilder (a, cb);
                }
@@ -2667,11 +2700,6 @@ namespace Mono.CSharp {
                                }
                        }
                }
-
-               public override void Register ()
-               {
-                       Parent.AddClassOrStruct (this);
-               }
        }
 
        /// <summary>
@@ -2680,11 +2708,17 @@ namespace Mono.CSharp {
        public sealed class StaticClass: Class {
                public StaticClass (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
                        Attributes attrs, Location l)
-                       : base (ns, parent, name, mod & ~Modifiers.STATIC, attrs, l)
+                       : base (ns, parent, name, mod, attrs, l)
                {
                        if (RootContext.Version == LanguageVersion.ISO_1) {
                                Report.FeatureIsNotStandardized (l, "static classes");
-                               Environment.Exit (1);
+                       }
+               }
+
+               protected override int AllowedModifiersProp {
+                       get {
+                               return Modifiers.NEW | Modifiers.PUBLIC | Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE |
+                                       Modifiers.STATIC | Modifiers.UNSAFE;
                        }
                }
 
@@ -2699,7 +2733,15 @@ namespace Mono.CSharp {
                                        continue;
                                }
 
-                               if ((m.ModFlags & Modifiers.STATIC) != 0)
+                               if ((m.ModFlags & Modifiers.PROTECTED) != 0)
+                                       Report.Warning (628, 4, m.Location, "'{0}': new protected member declared in static class", m.GetSignatureForError (this));
+
+                               if (m is Indexer) {
+                                       Report.Error (720, m.Location, "'{0}': cannot declare indexers in a static class", m.GetSignatureForError (this));
+                                       continue;
+                               }
+
+                               if ((m.ModFlags & Modifiers.STATIC) != 0 || m is Enum || m is Delegate)
                                        continue;
 
                                if (m is Constructor) {
@@ -2720,6 +2762,11 @@ namespace Mono.CSharp {
 
                public override TypeBuilder DefineType()
                {
+                       if ((ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) == (Modifiers.SEALED | Modifiers.STATIC)) {
+                               Report.Error (441, Location, "'{0}': a class cannot be both static and sealed", GetSignatureForError ());
+                               return null;
+                       }
+
                        TypeBuilder tb = base.DefineType ();
                        if (tb == null)
                                return null;
@@ -2737,7 +2784,7 @@ namespace Mono.CSharp {
                        return tb;
                }
 
-               public override TypeAttributes TypeAttr {
+               protected override TypeAttributes TypeAttr {
                        get {
                                return base.TypeAttr | TypeAttributes.Abstract | TypeAttributes.Sealed;
                        }
@@ -2745,9 +2792,7 @@ namespace Mono.CSharp {
        }
 
        public class Class : ClassOrStruct {
-               // <summary>
-               //   Modifiers allowed in a class declaration
-               // </summary>
+               // TODO: remove this and use only AllowedModifiersProp to fix partial classes bugs
                public const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -2758,61 +2803,105 @@ namespace Mono.CSharp {
                        Modifiers.SEALED |
                        Modifiers.UNSAFE;
 
-               // Information in the case we are an attribute type
-               AttributeUsageAttribute attribute_usage;
+               bool WasTransitError;
 
                public Class (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
                              Attributes attrs, Location l)
                        : base (ns, parent, name, attrs, Kind.Class, l)
                {
-                       int accmods;
-
-                       if (parent.Parent == null)
-                               accmods = Modifiers.INTERNAL;
-                       else
-                               accmods = Modifiers.PRIVATE;
-
-                       this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
-                       if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.SEALED)) == (Modifiers.ABSTRACT | Modifiers.SEALED)) {
-                               Report.Error (502, Location, "'{0}' cannot be both abstract and sealed", GetSignatureForError ());
-                       }
-
-                       attribute_usage = new AttributeUsageAttribute (AttributeTargets.All);
+                       this.ModFlags = mod;
                }
 
-               public override AttributeTargets AttributeTargets {
+               virtual protected int AllowedModifiersProp {
                        get {
-                               return AttributeTargets.Class;
+                               return AllowedModifiers;
                        }
                }
 
                public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
                {
-                       if (a.UsageAttribute != null) {
+                       if (a.Type == TypeManager.attribute_usage_type) {
                                if (ptype != TypeManager.attribute_type && !ptype.IsSubclassOf (TypeManager.attribute_type) &&
                                        TypeBuilder.FullName != "System.Attribute") {
                                        Report.Error (641, a.Location, "Attribute '{0}' is only valid on classes derived from System.Attribute", a.Name);
                                }
-                               attribute_usage = a.UsageAttribute;
                        }
 
+                       if (a.Type == TypeManager.conditional_attribute_type &&
+                               !(ptype == TypeManager.attribute_type || ptype.IsSubclassOf (TypeManager.attribute_type))) {
+                               Report.Error (1689, a.Location, "Attribute 'System.Diagnostics.ConditionalAttribute' is only valid on methods or attribute classes");
+                               return;
+                       }
+
+                       if (AttributeTester.IsAttributeExcluded (a.Type))
+                               return;
+
                        base.ApplyAttributeBuilder (a, cb);
                }
 
-               public AttributeUsageAttribute AttributeUsage {
-                       get {
-                               return attribute_usage;
+               public const TypeAttributes DefaultTypeAttributes =
+                       TypeAttributes.AutoLayout | TypeAttributes.Class;
+
+               public override TypeBuilder DefineType()
+               {
+                       if (InTransit) {
+                               if (WasTransitError)
+                                       return null;
+                               throw new CircularDepException (this);
+                       }
+
+                       if ((ModFlags & Modifiers.ABSTRACT) == Modifiers.ABSTRACT && (ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) != 0) {
+                               Report.Error (418, Location, "'{0}': an abstract class cannot be sealed or static", GetSignatureForError ());
+                               return null;
+                       }
+
+                       int accmods = Parent.Parent == null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
+                       ModFlags = Modifiers.Check (AllowedModifiersProp, ModFlags, accmods, Location);
+
+                       try {
+                               return base.DefineType ();
+                       }
+                       catch (CircularDepException e) {
+                               Report.SymbolRelatedToPreviousError (e.Container);
+                               Report.Error (146, Location, "Circular base class dependency involving '{0}' and '{1}'",
+                                       GetSignatureForError (), e.Container.GetSignatureForError ());
+                               WasTransitError = true;
+                               return null;
                        }
                }
 
-               public const TypeAttributes DefaultTypeAttributes =
-                       TypeAttributes.AutoLayout | TypeAttributes.Class;
+               /// Search for at least one defined condition in ConditionalAttribute of attribute class
+               /// Valid only for attribute classes.
+               public bool IsExcluded ()
+               {
+                       if ((caching_flags & Flags.Excluded_Undetected) == 0)
+                               return (caching_flags & Flags.Excluded) != 0;
+
+                       caching_flags &= ~Flags.Excluded_Undetected;
+
+                       if (OptAttributes == null)
+                               return false;
+
+                       Attribute[] attrs = OptAttributes.SearchMulti (TypeManager.conditional_attribute_type, ec);
+
+                       if (attrs == null)
+                               return false;
+
+                       foreach (Attribute a in attrs) {
+                               string condition = a.GetConditionalAttributeValue (Parent.EmitContext);
+                               if (RootContext.AllDefines.Contains (condition))
+                                       return false;
+                       }
+
+                       caching_flags |= Flags.Excluded;
+                       return true;
+               }
 
                //
                // FIXME: How do we deal with the user specifying a different
                // layout?
                //
-               public override TypeAttributes TypeAttr {
+               protected override TypeAttributes TypeAttr {
                        get {
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
@@ -2847,12 +2936,6 @@ namespace Mono.CSharp {
                        this.ModFlags |= Modifiers.SEALED;
                }
 
-               public override AttributeTargets AttributeTargets {
-                       get {
-                               return AttributeTargets.Struct;
-                       }
-               }
-
                public const TypeAttributes DefaultTypeAttributes =
                        TypeAttributes.SequentialLayout |
                        TypeAttributes.Sealed |
@@ -2863,17 +2946,38 @@ namespace Mono.CSharp {
                // in some cases (Sealed for example is mandatory for a class,
                // but what SequentialLayout can be changed
                //
-               public override TypeAttributes TypeAttr {
+               protected override TypeAttributes TypeAttr {
                        get {
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
+
+               public override TypeBuilder DefineType()
+               {
+                       if (InTransit) {
+                               InTransit = false;
+                               throw new CircularDepException (this);
+                       }
+
+                       try {
+                               return base.DefineType ();
+                       }
+                       catch (CircularDepException e) {
+                               InTransit = false;
+                               Report.SymbolRelatedToPreviousError (this);
+                               Error_TypeInListIsNotInterface (e.Container.Location, GetSignatureForError ());
+                               return null;
+                       }
+               }
        }
 
        /// <summary>
        ///   Interfaces
        /// </summary>
        public class Interface : TypeContainer, IMemberContainer {
+
+               bool WasTransitError;
+
                /// <summary>
                ///   Modifiers allowed in a class declaration
                /// </summary>
@@ -2899,32 +3003,60 @@ namespace Mono.CSharp {
                        this.ModFlags = Modifiers.Check (AllowedModifiers, mod, accmods, l);
                }
 
-               public override void Register ()
-               {
-                       Parent.AddInterface (this);
-               }
-
                public override PendingImplementation GetPendingImplementations ()
                {
                        return null;
                }
 
-               public override AttributeTargets AttributeTargets {
-                       get {
-                               return AttributeTargets.Interface;
-                       }
-               }
-
                public const TypeAttributes DefaultTypeAttributes =
                        TypeAttributes.AutoLayout |
                        TypeAttributes.Abstract |
                        TypeAttributes.Interface;
 
-               public override TypeAttributes TypeAttr {
+               protected override TypeAttributes TypeAttr {
                        get {
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
+
+               public override TypeBuilder DefineType()
+               {
+                       if (InTransit) {
+                               if (WasTransitError) 
+                                       return null;
+                               throw new CircularDepException (this);
+                       }
+
+                       try {
+                               return base.DefineType ();
+                       }
+                       catch (CircularDepException e) {
+                               Report.SymbolRelatedToPreviousError (e.Container);
+                               Report.Error (529, Location, "Inherited interface '{0}' causes a cycle in the interface hierarchy of '{1}'",
+                                       e.Container.GetSignatureForError (), GetSignatureForError ());
+                               WasTransitError = true;
+                               return null;
+                       }
+               }
+
+               protected override bool VerifyClsCompliance (DeclSpace ds)
+               {
+                       if (!base.VerifyClsCompliance (ds))
+                               return false;
+
+                       if (ifaces != null) {
+                               foreach (Type t in ifaces) {
+                                       if (AttributeTester.IsClsCompliant (t))
+                                               continue;
+
+                                       Report.SymbolRelatedToPreviousError (t);
+                                       Report.Warning (3027, 1, Location, "'{0}' is not CLS-compliant because base interface '{1}' is not CLS-compliant",
+                                               GetSignatureForError (), TypeManager.CSharpName (t));
+                               }
+                       }
+
+                       return true;
+               }
        }
 
        public abstract class MethodCore : MemberBase {
@@ -2943,7 +3075,7 @@ namespace Mono.CSharp {
                //
                // The method we're overriding if this is an override method.
                //
-               protected MethodInfo parent_method = null;
+               protected MethodInfo base_method = null;
 
                static string[] attribute_targets = new string [] { "method", "return" };
 
@@ -2999,39 +3131,45 @@ namespace Mono.CSharp {
                                return true;
 
                        // Is null for System.Object while compiling corlib and base interfaces
-                       if (Parent.ParentCache == null) {
+                       if (Parent.BaseCache == null) {
                                if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
                                        Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError (Parent));
                                }
                                return true;
                        }
 
-                       Type parent_ret_type = null;
-                       parent_method = FindOutParentMethod (Parent, ref parent_ret_type);
+                       Type base_ret_type = null;
+                       base_method = FindOutBaseMethod (Parent, ref base_ret_type);
 
                        // method is override
-                       if (parent_method != null) {
+                       if (base_method != null) {
 
                                if (!CheckMethodAgainstBase ())
                                        return false;
 
                                if ((ModFlags & Modifiers.NEW) == 0) {
-                                       if (MemberType != TypeManager.TypeToCoreType (parent_ret_type)) {
-                                               Report.SymbolRelatedToPreviousError (parent_method);
-                                               Report.Error (508, Location, GetSignatureForError (Parent) + ": cannot " +
-                                                       "change return type when overriding inherited member");
+                                       if (MemberType != TypeManager.TypeToCoreType (base_ret_type)) {
+                                               Report.SymbolRelatedToPreviousError (base_method);
+                                               if (this is PropertyBase) {
+                                                       Report.Error (1715, Location, "'{0}': type must be '{1}' to match overridden member '{2}'", 
+                                                               GetSignatureForError (), TypeManager.CSharpName (base_ret_type), TypeManager.CSharpSignature (base_method));
+                                               }
+                                               else {
+                                                       Report.Error (508, Location, GetSignatureForError (Parent) + ": cannot " +
+                                                               "change return type when overriding inherited member");
+                                               }
                                                return false;
                                        }
                                } else {
-                                       if (parent_method.IsAbstract && !IsInterface) {
-                                               Report.SymbolRelatedToPreviousError (parent_method);
+                                       if (base_method.IsAbstract && !IsInterface) {
+                                               Report.SymbolRelatedToPreviousError (base_method);
                                                Report.Error (533, Location, "'{0}' hides inherited abstract member", GetSignatureForError (Parent));
                                                return false;
                                        }
                                }
 
-                               if (parent_method.IsSpecialName && !(this is PropertyBase)) {
-                                       Report.Error (561, Location, "'{0}': cannot override '{1}' because it is a special compiler-generated method", GetSignatureForError (Parent), TypeManager.GetFullNameSignature (parent_method));
+                               if (base_method.IsSpecialName && !(this is PropertyBase)) {
+                                       Report.Error (561, Location, "'{0}': cannot override '{1}' because it is a special compiler-generated method", GetSignatureForError (Parent), TypeManager.GetFullNameSignature (base_method));
                                        return false;
                                }
 
@@ -3042,18 +3180,20 @@ namespace Mono.CSharp {
                                                Parent.Methods.HasGetHashCode = true;
                                }
 
-                               ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (parent_method);
-                               if (oa != null) {
-                                       EmitContext ec = new EmitContext (this.Parent, this.Parent, Location, null, null, ModFlags, false);
-                                       if (OptAttributes == null || !OptAttributes.Contains (TypeManager.obsolete_attribute_type, ec)) {
-                                               Report.SymbolRelatedToPreviousError (parent_method);
-                                               Report.Warning (672, 1, Location, "Member '{0}' overrides obsolete member. Add the Obsolete attribute to '{0}'", GetSignatureForError (Parent));
+                               if ((ModFlags & Modifiers.OVERRIDE) != 0) {
+                                       ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (base_method);
+                                       if (oa != null) {
+                                               EmitContext ec = new EmitContext (this.Parent, this.Parent, Location, null, null, ModFlags, false);
+                                               if (OptAttributes == null || !OptAttributes.Contains (TypeManager.obsolete_attribute_type, ec)) {
+                                                       Report.SymbolRelatedToPreviousError (base_method);
+                                                       Report.Warning (672, 1, Location, "Member '{0}' overrides obsolete member. Add the Obsolete attribute to '{0}'", GetSignatureForError (Parent));
+                                               }
                                        }
                                }
                                return true;
                        }
 
-                       MemberInfo conflict_symbol = Parent.FindMemberWithSameName (Name, !(this is Property));
+                       MemberInfo conflict_symbol = Parent.FindBaseMemberWithSameName (Name, !(this is Property));
                        if ((ModFlags & Modifiers.OVERRIDE) != 0) {
                                if (conflict_symbol != null) {
                                        Report.SymbolRelatedToPreviousError (conflict_symbol);
@@ -3097,10 +3237,10 @@ namespace Mono.CSharp {
                        bool ok = true;
 
                        // TODO: replace with GetSignatureForError 
-                       string name = parent_method.DeclaringType.Name + "." + parent_method.Name;
+                       string name = base_method.DeclaringType.Name + "." + base_method.Name;
 
                        if ((ModFlags & Modifiers.OVERRIDE) != 0){
-                               if (!(parent_method.IsAbstract || parent_method.IsVirtual)){
+                               if (!(base_method.IsAbstract || base_method.IsVirtual)){
                                        Report.Error (
                                                506, Location, Parent.MakeName (Name) +
                                                ": cannot override inherited member `" +
@@ -3111,38 +3251,30 @@ namespace Mono.CSharp {
                                
                                // Now we check that the overriden method is not final
                                
-                               if (parent_method.IsFinal) {
-                                       // This happens when implementing interface methods.
-                                       if (parent_method.IsHideBySig && parent_method.IsVirtual) {
-                                               Report.Error (
-                                                       506, Location, Parent.MakeName (Name) +
-                                                       ": cannot override inherited member `" +
-                                                       name + "' because it is not " +
-                                                       "virtual, abstract or override");
-                                       } else
-                                               Report.Error (239, Location, Parent.MakeName (Name) + " : cannot " +
-                                                             "override inherited member `" + name +
-                                                             "' because it is sealed.");
+                               if (base_method.IsFinal) {
+                                       Report.SymbolRelatedToPreviousError (base_method);
+                                       Report.Error (239, Location, "'{0}': cannot override inherited member '{1}' because it is sealed",
+                                                             GetSignatureForError (), TypeManager.CSharpSignature (base_method));
                                        ok = false;
                                }
                                //
                                // Check that the permissions are not being changed
                                //
                                MethodAttributes thisp = flags & MethodAttributes.MemberAccessMask;
-                               MethodAttributes parentp = parent_method.Attributes & MethodAttributes.MemberAccessMask;
+                               MethodAttributes base_classp = base_method.Attributes & MethodAttributes.MemberAccessMask;
 
-                               if (!CheckAccessModifiers (thisp, parentp, parent_method)) {
-                                       Error_CannotChangeAccessModifiers (Parent, parent_method, name);
+                               if (!CheckAccessModifiers (thisp, base_classp, base_method)) {
+                                       Error_CannotChangeAccessModifiers (Parent, base_method, name);
                                        ok = false;
                                }
                        }
 
                        if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0 && Name != "Finalize") {
                                ModFlags |= Modifiers.NEW;
-                               Report.SymbolRelatedToPreviousError (parent_method);
-                               if (!IsInterface && (parent_method.IsVirtual || parent_method.IsAbstract)) {
+                               Report.SymbolRelatedToPreviousError (base_method);
+                               if (!IsInterface && (base_method.IsVirtual || base_method.IsAbstract)) {
                                        if (RootContext.WarningLevel >= 2)
-                                               Report.Warning (114, Location, "'{0}' hides inherited member '{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword", GetSignatureForError (Parent), TypeManager.CSharpSignature (parent_method));
+                                               Report.Warning (114, Location, "'{0}' hides inherited member '{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword", GetSignatureForError (Parent), TypeManager.CSharpSignature (base_method));
                                } else
                                        Report.Warning (108, Location, "The keyword new is required on '{0}' because it hides inherited member", GetSignatureForError (Parent));
                        }
@@ -3150,9 +3282,9 @@ namespace Mono.CSharp {
                        return ok;
                }
                
-               protected bool CheckAccessModifiers (MethodAttributes thisp, MethodAttributes parentp, MethodInfo base_method)
+               protected bool CheckAccessModifiers (MethodAttributes thisp, MethodAttributes base_classp, MethodInfo base_method)
                {
-                       if ((parentp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
+                       if ((base_classp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
                                //
                                // when overriding protected internal, the method can be declared
                                // protected internal only within the same assembly
@@ -3165,7 +3297,7 @@ namespace Mono.CSharp {
                                                //
                                                
                                                return false;
-                                       } else if (thisp != parentp) {
+                                       } else if (thisp != base_classp) {
                                                //
                                                // same assembly, but other attributes differ - report an error
                                                //
@@ -3184,7 +3316,7 @@ namespace Mono.CSharp {
                                        //
                                        return false;
                                } else if ((thisp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem)) != 
-                                          (parentp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem))) {
+                                          (base_classp & ~(MethodAttributes.Family | MethodAttributes.FamORAssem))) {
                                        //
                                        // protected ok, but other attributes differ - report an error
                                        //
@@ -3192,11 +3324,11 @@ namespace Mono.CSharp {
                                }
                                return true;
                        } else {
-                               return (thisp == parentp);
+                               return (thisp == base_classp);
                        }
                }
                
-               void Error_CannotChangeAccessModifiers (TypeContainer parent, MethodInfo parent_method, string name)
+               void Error_CannotChangeAccessModifiers (TypeContainer parent, MethodInfo base_method, string name)
                {
                        //
                        // FIXME: report the old/new permissions?
@@ -3219,9 +3351,9 @@ namespace Mono.CSharp {
                protected abstract bool CheckForDuplications ();
 
                /// <summary>
-               /// Gets parent method and its return type
+               /// Gets base method and its return type
                /// </summary>
-               protected abstract MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type);
+               protected abstract MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type);
 
                protected virtual bool DoDefineParameters ()
                {
@@ -3272,7 +3404,12 @@ namespace Mono.CSharp {
                        }
 
                        if (!AttributeTester.IsClsCompliant (MemberType)) {
-                               Report.Error (3002, Location, "Return type of '{0}' is not CLS-compliant", GetSignatureForError ());
+                               if (this is PropertyBase)
+                                       Report.Error (3003, Location, "Type of `{0}' is not CLS-compliant",
+                                                     GetSignatureForError ());
+                               else
+                                       Report.Error (3002, Location, "Return type of '{0}' is not CLS-compliant",
+                                                     GetSignatureForError ());
                        }
 
                        AttributeTester.AreParametersCompliant (Parameters.FixedParameters, Location);
@@ -3315,10 +3452,23 @@ namespace Mono.CSharp {
                        }
 
                        Report.SymbolRelatedToPreviousError (method);
-                       Report.Error (111, Location, TypeContainer.Error111, Parent.Name, Name);
+                       if (this is Operator && method is Operator)
+                               Report.Error (557, Location, "Duplicate user-defined conversion in type '{0}'", Parent.Name);
+                       else
+                               Report.Error (111, Location, TypeContainer.Error111, Parent.Name, Name);
                        return true;
                }
 
+               public override bool IsUsed
+               {
+                       get {
+                               if (IsExplicitImpl)
+                                       return true;
+
+                               return base.IsUsed;
+                       }
+               }
+
                //
                // Returns a string that represents the signature for this 
                // member which should be used in XML documentation.
@@ -3543,7 +3693,8 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (a.Type == TypeManager.methodimpl_attr_type && a.IsInternalCall) {
+                       if (a.Type == TypeManager.methodimpl_attr_type &&
+                               (a.GetMethodImplOptions () & MethodImplOptions.InternalCall) != 0) {
                                MethodBuilder.SetImplementationFlags (MethodImplAttributes.InternalCall | MethodImplAttributes.Runtime);
                        }
 
@@ -3570,7 +3721,7 @@ namespace Mono.CSharp {
                                }
 
                                if (ReturnType != TypeManager.void_type) {
-                                       Report.Error (578, Location, "Conditional not valid on '{0}' because its return new ErrorData ( type is not void", GetSignatureForError ());
+                                       Report.Error (578, Location, "Conditional not valid on '{0}' because its return type is not void", GetSignatureForError ());
                                        return;
                                }
 
@@ -3651,6 +3802,11 @@ namespace Mono.CSharp {
                        if (!DoDefine ())
                                return false;
 
+                       if (RootContext.StdLib && (ReturnType == TypeManager.arg_iterator_type || ReturnType == TypeManager.typed_reference_type)) {
+                               Error1599 (Location, ReturnType);
+                               return false;
+                       }
+
                        if (!CheckBase ())
                                return false;
 
@@ -3662,12 +3818,17 @@ namespace Mono.CSharp {
                        if (!MethodData.Define (Parent))
                                return false;
 
+                       if (ReturnType == TypeManager.void_type && ParameterTypes.Length == 0 && 
+                               Name == "Finalize" && !(this is Destructor)) {
+                               Report.Warning (465, 1, Location, "Introducing a 'Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?");
+                       }
+
                        //
                        // Setup iterator if we are one
                        //
                        if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
                                Iterator iterator = new Iterator (
-                                       Parent, Name, MemberType, ParameterTypes,
+                                       Parent, Name, MemberType,
                                        ParameterInfo, ModFlags, block, Location);
 
                                if (!iterator.DefineIterator ())
@@ -3686,6 +3847,9 @@ namespace Mono.CSharp {
                            (RootContext.MainClass == null ||
                             RootContext.MainClass == Parent.TypeBuilder.FullName)){
                                 if (IsEntryPoint (MethodBuilder, ParameterInfo)) {
+                                        IMethodData md = TypeManager.GetMethod (MethodBuilder);
+                                        md.SetMemberIsUsed ();
+
                                         if (RootContext.EntryPoint == null) {
                                                 RootContext.EntryPoint = MethodBuilder;
                                                 RootContext.EntryPointLocation = Location;
@@ -3725,18 +3889,29 @@ namespace Mono.CSharp {
                        MethodData = null;
                }
 
-               protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+               public static void Error1599 (Location loc, Type t)
+               {
+                       Report.Error (1599, loc, "Method or delegate cannot return type '{0}'", TypeManager.CSharpName (t));
+               }
+
+               protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
                {
-                       MethodInfo mi = (MethodInfo) container.ParentCache.FindMemberToOverride (
+                       MethodInfo mi = (MethodInfo) container.BaseCache.FindMemberToOverride (
                                container.TypeBuilder, Name, ParameterTypes, false);
 
                        if (mi == null)
                                return null;
 
-                       parent_ret_type = mi.ReturnType;
+                       base_ret_type = mi.ReturnType;
                        return mi;
                }
 
+               public override bool MarkForDuplicationCheck ()
+               {
+                       caching_flags |= Flags.TestMethodDuplication;
+                       return true;
+               }
+
                protected override bool VerifyClsCompliance(DeclSpace ds)
                {
                        if (!base.VerifyClsCompliance (ds))
@@ -3793,6 +3968,20 @@ namespace Mono.CSharp {
                        }
                }
 
+               protected override bool CheckBase() {
+                       if (!base.CheckBase ())
+                               return false;
+
+                       // TODO: Destructor should derive from MethodCore
+                       if (base_method != null && (ModFlags & Modifiers.OVERRIDE) != 0 && Name == "Finalize" &&
+                               base_method.DeclaringType == TypeManager.object_type && !(this is Destructor)) {
+                               Report.Error (249, Location, "Do not override object.Finalize. Instead, provide a destructor");
+                               return false;
+                       }
+
+                       return true;
+               }
+
                public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
                {
                        return new EmitContext (
@@ -3814,7 +4003,7 @@ namespace Mono.CSharp {
 
                        caching_flags &= ~Flags.Excluded_Undetected;
 
-                       if (parent_method == null) {
+                       if (base_method == null) {
                                if (OptAttributes == null)
                                        return false;
 
@@ -3824,8 +4013,7 @@ namespace Mono.CSharp {
                                        return false;
 
                                foreach (Attribute a in attrs) {
-                                       string condition = a.GetConditionalAttributeValue (
-                                               Parent);
+                                       string condition = a.GetConditionalAttributeValue (Parent.EmitContext);
                                        if (RootContext.AllDefines.Contains (condition))
                                                return false;
                                }
@@ -3834,9 +4022,9 @@ namespace Mono.CSharp {
                                return true;
                        }
 
-                       IMethodData md = TypeManager.GetMethod (parent_method);
+                       IMethodData md = TypeManager.GetMethod (base_method);
                        if (md == null) {
-                               if (AttributeTester.IsConditionalMethodExcluded (parent_method)) {
+                               if (AttributeTester.IsConditionalMethodExcluded (base_method)) {
                                        caching_flags |= Flags.Excluded;
                                        return true;
                                }
@@ -3855,7 +4043,7 @@ namespace Mono.CSharp {
 
        public abstract class ConstructorInitializer {
                ArrayList argument_list;
-               protected ConstructorInfo parent_constructor;
+               protected ConstructorInfo base_constructor;
                Parameters parameters;
                Location loc;
                
@@ -3873,12 +4061,13 @@ namespace Mono.CSharp {
                        }
                }
 
-               public bool Resolve (ConstructorBuilder caller_builder, EmitContext ec)
+               public bool Resolve (ConstructorBuilder caller_builder, Block block, EmitContext ec)
                {
-                       Expression parent_constructor_group;
+                       Expression base_constructor_group;
                        Type t;
+                       bool error = false;
 
-                       ec.CurrentBlock = new ToplevelBlock (Block.Flags.Implicit, parameters, loc);
+                       ec.CurrentBlock = block;
 
                        if (argument_list != null){
                                foreach (Argument a in argument_list){
@@ -3901,40 +4090,40 @@ namespace Mono.CSharp {
                        } else
                                t = ec.ContainerType;
 
-                       parent_constructor_group = Expression.MemberLookup (
+                       base_constructor_group = Expression.MemberLookup (
                                ec, t, ".ctor", MemberTypes.Constructor,
                                BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                                loc);
                        
-                       if (parent_constructor_group == null){
-                               parent_constructor_group = Expression.MemberLookup (
-                                       ec, t, ".ctor", MemberTypes.Constructor,
+                       if (base_constructor_group == null){
+                               error = true;
+                               base_constructor_group = Expression.MemberLookup (
+                                       ec, t, null, t, ".ctor", MemberTypes.Constructor,
                                        BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly,
                                        loc);
+                       }
 
-                               if (parent_constructor_group != null)
-                                       Report.Error (
-                                               112, loc, "`{0}.{1}' is inaccessible due to " +
-                                               "its protection level", t.FullName, t.Name);
-                               else
-                                       Report.Error (
-                                               1501, loc, "Can not find a constructor for " +
-                                               "this argument list");
+                       int errors = Report.Errors;
+                       if (base_constructor_group != null)
+                               base_constructor = (ConstructorInfo) Invocation.OverloadResolve (
+                                       ec, (MethodGroupExpr) base_constructor_group, argument_list,
+                                       false, loc);
+                       
+                       if (base_constructor == null) {
+                               if (errors == Report.Errors)
+                                       Report.Error (1501, loc, "Can not find a constructor for this argument list");
                                return false;
                        }
-                       
-                       parent_constructor = (ConstructorInfo) Invocation.OverloadResolve (
-                               ec, (MethodGroupExpr) parent_constructor_group, argument_list,
-                               false, loc);
-                       
-                       if (parent_constructor == null){
-                               Report.Error (1501, loc,
-                                      "Can not find a constructor for this argument list");
+
+                       if (error) {
+                               Report.Error (122, loc, "`{0}' is inaccessible due to its protection level",
+                                             TypeManager.CSharpSignature (base_constructor));
+                               base_constructor = null;
                                return false;
                        }
 
-                       if (parent_constructor == caller_builder){
-                               Report.Error (516, String.Format ("Constructor `{0}' can not call itself", TypeManager.CSharpSignature (caller_builder)));
+                       if (base_constructor == caller_builder){
+                               Report.Error (516, loc, "Constructor `{0}' can not call itself", TypeManager.CSharpSignature (caller_builder));
                                return false;
                        }
                        
@@ -3943,74 +4132,14 @@ namespace Mono.CSharp {
 
                public void Emit (EmitContext ec)
                {
-                       if (parent_constructor != null){
+                       if (base_constructor != null){
                                ec.Mark (loc, false);
                                if (ec.IsStatic)
-                                       Invocation.EmitCall (ec, true, true, null, parent_constructor, argument_list, loc);
+                                       Invocation.EmitCall (ec, true, true, null, base_constructor, argument_list, loc);
                                else
-                                       Invocation.EmitCall (ec, true, false, ec.GetThis (loc), parent_constructor, argument_list, loc);
+                                       Invocation.EmitCall (ec, true, false, ec.GetThis (loc), base_constructor, argument_list, loc);
                        }
                }
-
-               /// <summary>
-               /// Method search for base ctor. (We do not cache it).
-               /// </summary>
-               Constructor GetOverloadedConstructor (TypeContainer tc)
-               {
-                       if (tc.InstanceConstructors == null)
-                               return null;
-
-                       foreach (Constructor c in tc.InstanceConstructors) {
-                               if (Arguments == null) {
-                                       if (c.ParameterTypes.Length == 0)
-                                               return c;
-
-                                       continue;
-                               }
-
-                               bool ok = true;
-
-                               int count = c.ParameterInfo.Count;
-                               if ((count > 0) &&
-                                   c.ParameterInfo.ParameterModifier (count - 1) == Parameter.Modifier.PARAMS) {
-                                       for (int i = 0; i < count-1; i++)
-                                               if (c.ParameterTypes [i] != ((Argument)Arguments [i]).Type) {
-                                                       ok = false;
-                                                       break;
-                                               }
-                               } else {
-                                       if (c.ParameterTypes.Length != Arguments.Count)
-                                               continue;
-
-                                       for (int i = 0; i < Arguments.Count; ++i)
-                                               if (c.ParameterTypes [i] != ((Argument)Arguments [i]).Type) {
-                                                       ok = false;
-                                                       break;
-                                               }
-                               }
-
-                               if (!ok)
-                                       continue;
-
-                               return c;
-                       }
-
-                       return null;
-               }
-
-               //TODO: implement caching when it will be necessary
-               public virtual void CheckObsoleteAttribute (TypeContainer tc, Location loc)
-               {
-                       Constructor ctor = GetOverloadedConstructor (tc);
-                       if (ctor == null)
-                               return;
-
-                       ObsoleteAttribute oa = ctor.GetObsoleteAttribute (tc);
-                       if (oa == null)
-                               return;
-
-                       AttributeTester.Report_ObsoleteMessage (oa, ctor.GetSignatureForError (), loc);
-               }
        }
 
        public class ConstructorBaseInitializer : ConstructorInitializer {
@@ -4018,24 +4147,6 @@ namespace Mono.CSharp {
                        base (argument_list, pars, l)
                {
                }
-
-               public override void CheckObsoleteAttribute(TypeContainer tc, Location loc) {
-                       if (parent_constructor == null)
-                               return;
-
-                       TypeContainer type_ds = TypeManager.LookupTypeContainer (tc.TypeBuilder.BaseType);
-                       if (type_ds == null) {
-                               ObsoleteAttribute oa = AttributeTester.GetMemberObsoleteAttribute (parent_constructor);
-
-                               if (oa != null)
-                                       AttributeTester.Report_ObsoleteMessage (oa, TypeManager.CSharpSignature (parent_constructor), loc);
-
-                               return;
-                       }
-
-                       base.CheckObsoleteAttribute (type_ds, loc);
-               }
-
        }
 
        public class ConstructorThisInitializer : ConstructorInitializer {
@@ -4249,6 +4360,15 @@ namespace Mono.CSharp {
                                return;
                        }
 
+                       // If this is a non-static `struct' constructor and doesn't have any
+                       // initializer, it must initialize all of the struct's fields.
+                       if ((Parent.Kind == Kind.Struct) &&
+                           ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
+                               Block.AddThisVariable (Parent, Location);
+
+                       if (block != null)
+                               block.ResolveMeta (ec, ParameterInfo);
+
                        if ((ModFlags & Modifiers.STATIC) == 0){
                                if (Parent.Kind == Kind.Class && Initializer == null)
                                        Initializer = new ConstructorBaseInitializer (
@@ -4260,12 +4380,13 @@ namespace Mono.CSharp {
                                // `this' access
                                //
                                ec.IsStatic = true;
-                               if (Initializer != null && !Initializer.Resolve (ConstructorBuilder, ec))
+                               if ((Initializer != null) &&
+                                   !Initializer.Resolve (ConstructorBuilder, block, ec))
                                        return;
                                ec.IsStatic = false;
                        }
 
-                       Parameters.LabelParameters (ec, ConstructorBuilder, Location);
+                       Parameters.LabelParameters (ec, ConstructorBuilder);
                        
                        SourceMethod source = SourceMethod.Create (
                                Parent, ConstructorBuilder, block);
@@ -4285,10 +4406,9 @@ namespace Mono.CSharp {
                                }
                        }
                        if (Initializer != null) {
-                               if (GetObsoleteAttribute (Parent) == null && Parent.GetObsoleteAttribute (Parent.Parent) == null)
-                                       Initializer.CheckObsoleteAttribute (Parent, Location);
-                               else
+                               if (GetObsoleteAttribute () != null || Parent.GetObsoleteAttribute (Parent) != null)
                                        ec.TestObsoleteMethodUsage = false;
+
                                Initializer.Emit (ec);
                        }
                        
@@ -4298,12 +4418,6 @@ namespace Mono.CSharp {
                        if (OptAttributes != null) 
                                OptAttributes.Emit (ec, this);
 
-                       // If this is a non-static `struct' constructor and doesn't have any
-                       // initializer, it must initialize all of the struct's fields.
-                       if ((Parent.Kind == Kind.Struct) &&
-                           ((ModFlags & Modifiers.STATIC) == 0) && (Initializer == null))
-                               Block.AddThisVariable (Parent, Location);
-
                        ec.EmitTopBlock (block, ParameterInfo, Location);
 
                        if (source != null)
@@ -4321,7 +4435,7 @@ namespace Mono.CSharp {
                }
 
                // Is never override
-               protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+               protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
                {
                        return null;
                }
@@ -4391,7 +4505,7 @@ namespace Mono.CSharp {
 
                public ObsoleteAttribute GetObsoleteAttribute ()
                {
-                       return null;
+                       return GetObsoleteAttribute (Parent);
                }
 
                public bool IsExcluded(EmitContext ec)
@@ -4421,6 +4535,7 @@ namespace Mono.CSharp {
                string GetSignatureForError (TypeContainer tc);
                bool IsExcluded (EmitContext ec);
                bool IsClsCompliaceRequired (DeclSpace ds);
+               void SetMemberIsUsed ();
        }
 
        //
@@ -4475,20 +4590,39 @@ namespace Mono.CSharp {
                        Type[] ParameterTypes = method.ParameterTypes;
 
                        if (container.Pending != null){
-                               if (member is Indexer)
+                               if (member is Indexer) // TODO: test it, but it should work without this IF
                                        implementing = container.Pending.IsInterfaceIndexer (
-                                               member.InterfaceType, method.ReturnType, ParameterTypes);
+                                               member.InterfaceType, method.ReturnType, ParameterInfo);
                                else
                                        implementing = container.Pending.IsInterfaceMethod (
-                                               member.InterfaceType, name, method.ReturnType, ParameterTypes);
+                                               member.InterfaceType, name, method.ReturnType, ParameterInfo);
 
                                if (member.InterfaceType != null){
                                        if (implementing == null){
-                                               Report.Error (539, method.Location,
-                                                             "'{0}' in explicit interface declaration is not an interface", method_name);
+                                               if (member is PropertyBase) {
+                                                       Report.Error (550, method.Location, "'{0}' is an accessor not found in interface member '{1}'",
+                                                               method.GetSignatureForError (container), member.Name);
+
+                                               } else {
+                                                       Report.Error (539, method.Location,
+                                                               "'{0}' in explicit interface declaration is not a member of interface", member.GetSignatureForError () );
+                                               }
+                                               return false;
+                                       }
+                                       if (implementing.IsSpecialName && !((member is PropertyBase || member is EventProperty))) {
+                                               Report.SymbolRelatedToPreviousError (implementing);
+                                               Report.Error (683, method.Location, "'{0}' explicit method implementation cannot implement '{1}' because it is an accessor",
+                                                       member.GetSignatureForError (), TypeManager.CSharpSignature (implementing));
                                                return false;
                                        }
                                        method_name = member.InterfaceType.FullName + "." + name;
+                               } else {
+                                       if (implementing != null && method is AbstractPropertyEventMethod && !implementing.IsSpecialName) {
+                                               Report.SymbolRelatedToPreviousError (implementing);
+                                               Report.Error (686, method.Location, "Accessor '{0}' cannot implement interface member '{1}' for type '{2}'. Use an explicit interface implementation",
+                                                       method.GetSignatureForError (container), TypeManager.CSharpSignature (implementing), container.GetSignatureForError ());
+                                               return false;
+                                       }
                                }
                        }
 
@@ -4576,11 +4710,11 @@ namespace Mono.CSharp {
                                if (member is Indexer) {
                                        container.Pending.ImplementIndexer (
                                                member.InterfaceType, builder, method.ReturnType,
-                                               ParameterTypes, member.IsExplicitImpl);
+                                               ParameterInfo, member.IsExplicitImpl);
                                } else
                                        container.Pending.ImplementMethod (
                                                member.InterfaceType, name, method.ReturnType,
-                                               ParameterTypes, member.IsExplicitImpl);
+                                               ParameterInfo, member.IsExplicitImpl);
 
                                if (member.IsExplicitImpl)
                                        container.TypeBuilder.DefineMethodOverride (
@@ -4641,7 +4775,7 @@ namespace Mono.CSharp {
                        else
                                ec = method.CreateEmitContext (container, null);
 
-                       if (method.GetObsoleteAttribute () != null || container.GetObsoleteAttribute (container.Parent) != null)
+                       if (method.GetObsoleteAttribute () != null || container.GetObsoleteAttribute (container) != null)
                                ec.TestObsoleteMethodUsage = false;
 
                        Location loc = method.Location;
@@ -4651,9 +4785,8 @@ namespace Mono.CSharp {
                                OptAttributes.Emit (ec, kind);
 
                        if (member is MethodCore)
-                               ((MethodCore) member).Parameters.LabelParameters (ec, MethodBuilder, loc);
+                               ((MethodCore) member).Parameters.LabelParameters (ec, MethodBuilder);
 
-                       SymbolWriter sw = CodeGen.SymbolWriter;
                        ToplevelBlock block = method.Block;
                        
                        //
@@ -4732,10 +4865,10 @@ namespace Mono.CSharp {
                                        "Finalize", MemberTypes.Method, Expression.AllBindingFlags, method.Location);
 
                                if (member_lookup != null){
-                                       MethodGroupExpr parent_destructor = ((MethodGroupExpr) member_lookup);
+                                       MethodGroupExpr base_destructor = ((MethodGroupExpr) member_lookup);
                                
                                        ig.Emit (OpCodes.Ldarg_0);
-                                       ig.Emit (OpCodes.Call, (MethodInfo) parent_destructor.Methods [0]);
+                                       ig.Emit (OpCodes.Call, (MethodInfo) base_destructor.Methods [0]);
                                }
                        }
                        
@@ -4745,6 +4878,7 @@ namespace Mono.CSharp {
                }
        }
 
+       // Should derive from MethodCore
        public class Destructor : Method {
 
                public Destructor (TypeContainer ds, Expression return_type, int mod,
@@ -4776,30 +4910,44 @@ namespace Mono.CSharp {
                // The "short" name of this property / indexer / event.  This is the
                // name without the explicit interface.
                //
-               public string ShortName;
+               public string ShortName {
+                       get { return MemberName.Name; }
+                       set {
+                               SetMemberName (new MemberName (MemberName.Left, value));
+                       }
+               }
 
                //
                // The type of this property / indexer / event
                //
-               public Type MemberType;
+               Type member_type;
+               public Type MemberType {
+                       get {
+                               if (member_type == null && Type != null) {
+                                       EmitContext ec = Parent.EmitContext;
+                                       bool old_unsafe = ec.InUnsafe;
+                                       ec.InUnsafe = InUnsafe;
+                                       Type = Type.ResolveAsTypeTerminal (ec, false);
+                                       ec.InUnsafe = old_unsafe;
 
-               //
-               // If true, this is an explicit interface implementation
-               //
-               public bool IsExplicitImpl = false;
+                                       member_type = Type == null ? null : Type.Type;
+                               }
+                               return member_type;
+                       }
+               }
 
                //
-               // The name of the interface we are explicitly implementing
+               // Whether this is an interface member.
                //
-               public MemberName ExplicitInterfaceName = null;
+               public bool IsInterface;
 
                //
-               // Whether this is an interface member.
+               // If true, this is an explicit interface implementation
                //
-               public bool IsInterface;
+               public bool IsExplicitImpl;
 
                //
-               // If true, the interface type we are explicitly implementing
+               // The interface type we are explicitly implementing
                //
                public Type InterfaceType = null;
 
@@ -4814,14 +4962,7 @@ namespace Mono.CSharp {
                        explicit_mod_flags = mod;
                        Type = type;
                        ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
-
-                       // Check for explicit interface implementation
-                       if (MemberName.Left != null) {
-                               ExplicitInterfaceName = MemberName.Left;
-                               ShortName = MemberName.Name;
-                               IsExplicitImpl = true;
-                       } else
-                               ShortName = Name;
+                       IsExplicitImpl = (MemberName.Left != null);
                }
 
                protected virtual bool CheckBase ()
@@ -4903,23 +5044,15 @@ namespace Mono.CSharp {
                                        MethodAttributes.NewSlot |
                                        MethodAttributes.Virtual;
                        } else {
-                               if (!Parent.MethodModifiersValid (ModFlags, Name, Location))
+                               if (!Parent.MethodModifiersValid (this))
                                        return false;
 
                                flags = Modifiers.MethodAttr (ModFlags);
                        }
 
-                       // Lookup Type, verify validity
-                       bool old_unsafe = ec.InUnsafe;
-                       ec.InUnsafe = InUnsafe;
-                       Type = Type.ResolveAsTypeTerminal (ec, false);
-                       ec.InUnsafe = old_unsafe;
-
-                       if (Type == null)
+                       if (MemberType == null)
                                return false;
 
-                       MemberType = Type.Type;
-
                        if ((Parent.ModFlags & Modifiers.SEALED) != 0){
                                if ((ModFlags & (Modifiers.VIRTUAL|Modifiers.ABSTRACT)) != 0){
                                        Report.Error (549, Location, "Virtual method can not be contained in sealed class");
@@ -4929,11 +5062,12 @@ namespace Mono.CSharp {
                        
                        // verify accessibility
                        if (!Parent.AsAccessible (MemberType, ModFlags)) {
+                               Report.SymbolRelatedToPreviousError (MemberType);
                                if (this is Property)
                                        Report.Error (53, Location,
                                                      "Inconsistent accessibility: property type `" +
                                                      TypeManager.CSharpName (MemberType) + "' is less " +
-                                                     "accessible than property `" + Name + "'");
+                                                     "accessible than property `" + GetSignatureForError () + "'");
                                else if (this is Indexer)
                                        Report.Error (54, Location,
                                                      "Inconsistent accessibility: indexer return type `" +
@@ -4963,7 +5097,7 @@ namespace Mono.CSharp {
                                return false;
 
                        if (IsExplicitImpl) {
-                               Expression expr = ExplicitInterfaceName.GetTypeExpression (Location);
+                               Expression expr = MemberName.Left.GetTypeExpression (Location);
                                TypeExpr texpr = expr.ResolveAsTypeTerminal (ec, false);
                                if (texpr == null)
                                        return false;
@@ -4974,14 +5108,6 @@ namespace Mono.CSharp {
                                        Report.Error (538, Location, "'{0}' in explicit interface declaration is not an interface", TypeManager.CSharpName (InterfaceType));
                                        return false;
                                }
-
-#if FIXME
-                               // Compute the full name that we need to export.
-                               if (InterfaceType.FullName != ExplicitInterfaceName) {
-                                       ExplicitInterfaceName = InterfaceType.FullName;
-                                       UpdateMemberName ();
-                               }
-#endif
                                
                                if (!Parent.VerifyImplements (InterfaceType, ShortName, Name, Location))
                                        return false;
@@ -4992,14 +5118,6 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               /// <summary>
-               /// The name of the member can be changed during definition (see IndexerName attribute)
-               /// </summary>
-               protected virtual void UpdateMemberName ()
-               {
-                       MemberName.Name = ShortName;
-               }
-
                public override string GetSignatureForError (TypeContainer tc)
                {
                        return String.Concat (tc.Name, '.', base.GetSignatureForError (tc));
@@ -5043,14 +5161,13 @@ namespace Mono.CSharp {
                [Flags]
                public enum Status : byte {
                        ASSIGNED = 1,
-                       USED = 2,
                        HAS_OFFSET = 4          // Used by FieldMember.
                }
 
                static string[] attribute_targets = new string [] { "field" };
 
                /// <summary>
-               ///  Symbol with same name in parent class/struct
+               ///  Symbol with same name in base class/struct
                /// </summary>
                public MemberInfo conflict_symbol;
 
@@ -5119,9 +5236,14 @@ namespace Mono.CSharp {
                        else
                                e = new ArrayCreation (Type, "", (ArrayList)init, Location);
 
-                       ec.IsFieldInitializer = true;
-                       e = e.DoResolve (ec);
-                       ec.IsFieldInitializer = false;
+                       EmitContext parent_ec = Parent.EmitContext;
+
+                       bool old_is_static = parent_ec.IsStatic;
+                       parent_ec.IsStatic = ec.IsStatic;
+                       parent_ec.IsFieldInitializer = true;
+                       e = e.DoResolve (parent_ec);
+                       parent_ec.IsFieldInitializer = false;
+                       parent_ec.IsStatic = old_is_static;
 
                        init_expr = e;
                        init_expr_initialized = true;
@@ -5138,7 +5260,7 @@ namespace Mono.CSharp {
                        if (IsInterface)
                                return true;
  
-                       conflict_symbol = Parent.FindMemberWithSameName (Name, false);
+                       conflict_symbol = Parent.FindBaseMemberWithSameName (Name, false);
                        if (conflict_symbol == null) {
                                if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
                                        Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError (Parent));
@@ -5147,26 +5269,13 @@ namespace Mono.CSharp {
                        }
  
                        if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0) {
-                               Report.SymbolRelatedToPreviousError (conflict_symbol);
-                               Report.Warning (108, Location, "The keyword new is required on '{0}' because it hides inherited member", GetSignatureForError (Parent));
-                       }
+                               Report.SymbolRelatedToPreviousError (conflict_symbol);
+                               Report.Warning (108, Location, "The keyword new is required on '{0}' because it hides inherited member", GetSignatureForError (Parent));
+                       }
  
                        return true;
                }
 
-               protected override bool DoDefine ()
-               {
-                       if (!base.DoDefine ())
-                               return false;
-
-                       if (MemberType == TypeManager.void_type) {
-                               Report.Error (1547, Location,
-                                             "Keyword 'void' cannot be used in this context");
-                               return false;
-                       }
-                       return true;
-               }
-
                public override string GetSignatureForError ()
                {
                        if (FieldBuilder == null) {
@@ -5175,6 +5284,15 @@ namespace Mono.CSharp {
                        return TypeManager.GetFullNameSignature (FieldBuilder);
                }
 
+               protected virtual bool IsFieldClsCompliant {
+                       get {
+                               if (FieldBuilder == null)
+                                       return true;
+
+                               return AttributeTester.IsClsCompliant (FieldBuilder.FieldType);
+                       }
+               }
+
                public override string[] ValidAttributeTargets {
                        get {
                                return attribute_targets;
@@ -5186,11 +5304,7 @@ namespace Mono.CSharp {
                        if (!base.VerifyClsCompliance (ds))
                                return false;
 
-                       if (FieldBuilder == null) {
-                               return true;
-                       }
-
-                       if (!AttributeTester.IsClsCompliant (FieldBuilder.FieldType)) {
+                       if (!IsFieldClsCompliant) {
                                Report.Error (3003, Location, "Type of '{0}' is not CLS-compliant", GetSignatureForError ());
                        }
                        return true;
@@ -5205,12 +5319,12 @@ namespace Mono.CSharp {
 
        public abstract class FieldMember: FieldBase
        {
-               
-
                protected FieldMember (TypeContainer parent, Expression type, int mod,
                        int allowed_mod, MemberName name, object init, Attributes attrs, Location loc)
-                       : base (parent, type, mod, allowed_mod, name, init, attrs, loc)
+                       : base (parent, type, mod, allowed_mod | Modifiers.ABSTRACT, name, init, attrs, loc)
                {
+                       if ((mod & Modifiers.ABSTRACT) != 0)
+                               Report.Error (681, loc, "The modifier 'abstract' is not valid on fields. Try using a property instead");
                }
 
                public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
@@ -5229,6 +5343,14 @@ namespace Mono.CSharp {
                                        return;
                                }
                        }
+
+#if NET_2_0
+                       if (a.Type == TypeManager.fixed_buffer_attr_type) {
+                               Report.Error (1716, Location, "Do not use 'System.Runtime.CompilerServices.FixedBuffer' attribute. Use the 'fixed' field modifier instead");
+                               return;
+                       }
+#endif
+
                        base.ApplyAttributeBuilder (a, cb);
                }
 
@@ -5239,14 +5361,13 @@ namespace Mono.CSharp {
                        if (ec == null)
                                throw new InternalErrorException ("FieldMember.Define called too early");
 
-                       bool old_unsafe = ec.InUnsafe;
-                       ec.InUnsafe = InUnsafe;
-                       TypeExpr texpr = Type.ResolveAsTypeTerminal (ec, false);
-                       if (texpr == null)
+                       if (MemberType == null)
                                return false;
 
-                       MemberType = texpr.ResolveType (ec);
-                       ec.InUnsafe = old_unsafe;
+                       if (MemberType == TypeManager.void_type) {
+                               Report.Error (1547, Location, "Keyword 'void' cannot be used in this context");
+                               return false;
+                       }
 
                        if (!CheckBase ())
                                return false;
@@ -5270,6 +5391,11 @@ namespace Mono.CSharp {
 
                public override void Emit ()
                {
+                       if (OptAttributes != null) {
+                               EmitContext ec = new EmitContext (Parent, Location, null, FieldBuilder.FieldType, ModFlags);
+                               OptAttributes.Emit (ec, this);
+                       }
+
                        if (Parent.HasExplicitLayout && ((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0) {
                                Report.Error (625, Location, "'{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.", GetSignatureForError ());
                        }
@@ -5285,6 +5411,177 @@ namespace Mono.CSharp {
                }
        }
 
+       interface IFixedBuffer
+       {
+               FieldInfo Element { get; }
+               Type ElementType { get; }
+       }
+
+       public class FixedFieldExternal: IFixedBuffer
+       {
+               FieldInfo element_field;
+
+               public FixedFieldExternal (FieldInfo fi)
+               {
+                       element_field = fi.FieldType.GetField (FixedField.FixedElementName);
+               }
+
+               #region IFixedField Members
+
+               public FieldInfo Element {
+                       get {
+                               return element_field;
+                       }
+               }
+
+               public Type ElementType {
+                       get {
+                               return element_field.FieldType;
+                       }
+               }
+
+               #endregion
+       }
+
+       /// <summary>
+       /// Fixed buffer implementation
+       /// </summary>
+       public class FixedField: FieldMember, IFixedBuffer
+       {
+               public const string FixedElementName = "FixedElementField";
+               static int GlobalCounter = 0;
+               static object[] ctor_args = new object[] { (short)LayoutKind.Sequential };
+               static FieldInfo[] fi;
+
+               TypeBuilder fixed_buffer_type;
+               FieldBuilder element;
+               Expression size_expr;
+               int buffer_size;
+
+               const int AllowedModifiers =
+                       Modifiers.NEW |
+                       Modifiers.PUBLIC |
+                       Modifiers.PROTECTED |
+                       Modifiers.INTERNAL |
+                       Modifiers.PRIVATE;
+
+               public FixedField (TypeContainer parent, Expression type, int mod, string name,
+                       Expression size_expr, Attributes attrs, Location loc):
+                       base (parent, type, mod, AllowedModifiers, new MemberName (name), null, attrs, loc)
+               {
+                       if (RootContext.Version == LanguageVersion.ISO_1)
+                               Report.FeatureIsNotStandardized (loc, "fixed sized buffers");
+
+                       this.size_expr = size_expr;
+               }
+
+               public override bool Define()
+               {
+#if !NET_2_0
+                       if ((ModFlags & (Modifiers.PUBLIC | Modifiers.PROTECTED)) != 0)
+                               Report.Warning (-23, Location, "Only private or internal fixed sized buffers are supported by .NET 1.x");
+#endif
+
+                       if (Parent.Kind != Kind.Struct) {
+                               Report.Error (1642, Location, "Fixed buffer fields may only be members of structs");
+                               return false;
+                       }
+
+                       if (!base.Define ())
+                               return false;
+
+                       if (!TypeManager.IsPrimitiveType (MemberType)) {
+                               Report.Error (1663, Location, "Fixed sized buffer type must be one of the following: bool, byte, short, int, long, char, sbyte, ushort, uint, ulong, float or double");
+                               return false;
+                       }
+
+                       Expression e = size_expr.Resolve (Parent.EmitContext);
+                       if (e == null)
+                               return false;
+
+                       Constant c = e as Constant;
+                       if (c == null) {
+                               Report.Error (133, Location, "The expression being assigned to '{0}' must be constant", GetSignatureForError ());
+                               return false;
+                       }
+
+                       IntConstant buffer_size_const = c.ToInt (Location);
+                       if (buffer_size_const == null)
+                               return false;
+
+                       buffer_size = buffer_size_const.Value;
+
+                       if (buffer_size <= 0) {
+                               Report.Error (1665, Location, "Fixed sized buffer '{0}' must have a length greater than zero", GetSignatureForError ());
+                               return false;
+                       }
+
+                       int type_size = Expression.GetTypeSize (MemberType);
+
+                       if (buffer_size > int.MaxValue / type_size) {
+                               Report.Error (1664, Location, "Fixed sized buffer of length '{0}' and type '{1}' exceeded 2^31 limit",
+                                       buffer_size.ToString (), TypeManager.CSharpName (MemberType));
+                               return false;
+                       }
+
+                       buffer_size *= type_size;
+
+                       // Define nested
+                       string name = String.Format ("<{0}>__FixedBuffer{1}", Name, GlobalCounter++);
+
+                       fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name,
+                               TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, TypeManager.value_type);
+                       element = fixed_buffer_type.DefineField (FixedElementName, MemberType, FieldAttributes.Public);
+                       RootContext.RegisterCompilerGeneratedType (fixed_buffer_type);
+
+                       FieldBuilder = Parent.TypeBuilder.DefineField (Name, fixed_buffer_type, Modifiers.FieldAttr (ModFlags));
+                       TypeManager.RegisterFieldBase (FieldBuilder, this);
+
+                       return true;
+               }
+
+               public override void Emit()
+               {
+                       if (fi == null)
+                               fi = new FieldInfo [] { TypeManager.struct_layout_attribute_type.GetField ("Size") };
+
+                       object[] fi_val = new object[1];
+                       fi_val [0] = buffer_size;
+
+                       CustomAttributeBuilder cab = new CustomAttributeBuilder (TypeManager.struct_layout_attribute_ctor, 
+                               ctor_args, fi, fi_val);
+                       fixed_buffer_type.SetCustomAttribute (cab);
+
+#if NET_2_0
+                       cab = new CustomAttributeBuilder (TypeManager.fixed_buffer_attr_ctor, new object[] { MemberType, buffer_size } );
+                       FieldBuilder.SetCustomAttribute (cab);
+#endif
+                       base.Emit ();
+               }
+
+               protected override bool IsFieldClsCompliant {
+                       get {
+                               return false;
+                       }
+               }
+
+               #region IFixedField Members
+
+               public FieldInfo Element {
+                       get {
+                               return element;
+                       }
+               }
+
+               public Type ElementType {
+                       get {
+                               return MemberType;
+                       }
+               }
+
+               #endregion
+       }
+
        //
        // The Field class is used to represents class/struct fields during parsing.
        //
@@ -5386,16 +5683,16 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override void Emit ()
+               protected override bool VerifyClsCompliance (DeclSpace ds)
                {
-                       if (OptAttributes != null) {
-                               EmitContext ec = new EmitContext (
-                                       Parent, Location, null, FieldBuilder.FieldType,
-                                       ModFlags);
-                               OptAttributes.Emit (ec, this);
+                       if (!base.VerifyClsCompliance (ds))
+                               return false;
+
+                       if ((ModFlags & Modifiers.VOLATILE) != 0) {
+                               Report.Warning (3026, 1, Location, "CLS-compliant field '{0}' cannot be volatile", GetSignatureForError ());
                        }
 
-                       base.Emit ();
+                       return true;
                }
        }
 
@@ -5461,14 +5758,12 @@ namespace Mono.CSharp {
 
                static MemberName SetupName (string prefix, MemberBase member)
                {
-                       MemberName name = member.MemberName.Clone ();
-                       name.Name = prefix + member.ShortName;
-                       return name;
+                       return new MemberName (member.MemberName.Left, prefix + member.ShortName);
                }
 
                public void UpdateName (MemberBase member)
                {
-                       MemberName.Name = prefix + member.ShortName;
+                       SetMemberName (SetupName (prefix, member));
                }
 
                #region IMethodData Members
@@ -5550,7 +5845,7 @@ namespace Mono.CSharp {
 
                public virtual void Emit (TypeContainer container)
                {
-                       method_data.Emit (container, this);
+                       EmitMethod (container);
 
                        if (declarative_security != null) {
                                foreach (DictionaryEntry de in declarative_security) {
@@ -5561,6 +5856,11 @@ namespace Mono.CSharp {
                        block = null;
                }
 
+               protected virtual void EmitMethod (TypeContainer container)
+               {
+                       method_data.Emit (container, this);
+               }
+
                public override bool IsClsCompliaceRequired(DeclSpace ds)
                {
                        return false;
@@ -5585,6 +5885,16 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               public override bool IsUsed
+               {
+                       get {
+                               if (IsDummy)
+                                       return false;
+
+                               return base.IsUsed;
+                       }
+               }
+
                public new Location Location { 
                        get {
                                return base.Location;
@@ -5673,7 +5983,7 @@ namespace Mono.CSharp {
                        {
                                if (a.Target == AttributeTargets.Parameter) {
                                        if (param_attr == null)
-                                               param_attr = new ImplicitParameter (method_data.MethodBuilder);
+                                               param_attr = new ImplicitParameter (method_data.MethodBuilder, method.Location);
 
                                        param_attr.ApplyAttributeBuilder (a, cb);
                                        return;
@@ -5685,13 +5995,18 @@ namespace Mono.CSharp {
                        protected virtual InternalParameters GetParameterInfo (EmitContext ec)
                        {
                                Parameter [] parms = new Parameter [1];
-                               parms [0] = new Parameter (method.Type, "value", Parameter.Modifier.NONE, null);
-                               Parameters parameters = new Parameters (parms, null, method.Location);
+                               parms [0] = new Parameter (method.Type, "value", Parameter.Modifier.NONE, null, method.Location);
+                               Parameters parameters = new Parameters (parms, null);
+
+                               bool old_unsafe = ec.InUnsafe;
+                               ec.InUnsafe = InUnsafe;
                                Type [] types = parameters.GetParameterInfo (ec);
+                               ec.InUnsafe = old_unsafe;
+
                                return new InternalParameters (types, parameters);
                        }
 
-                       public override MethodBuilder Define(TypeContainer container)
+                       public override MethodBuilder Define (TypeContainer container)
                        {
                                if (container.EmitContext == null)
                                        throw new InternalErrorException ("SetMethod.Define called too early");
@@ -5741,6 +6056,7 @@ namespace Mono.CSharp {
                                : base (method, prefix)
                        {
                                this.method = method;
+                               Parent = method.Parent;
                        }
 
                        public PropertyMethod (MethodCore method, Accessor accessor,
@@ -5748,11 +6064,11 @@ namespace Mono.CSharp {
                                : base (method, accessor, prefix)
                        {
                                this.method = method;
+                               Parent = method.Parent;
                                this.ModFlags = accessor.ModFlags;
 
                                if (accessor.ModFlags != 0 && RootContext.Version == LanguageVersion.ISO_1) {
                                        Report.FeatureIsNotStandardized (Location, "accessor modifiers");
-                                       Environment.Exit (1);
                                }
                        }
 
@@ -5779,12 +6095,17 @@ namespace Mono.CSharp {
                                //
                                // Check for custom access modifier
                                //
-                                if (ModFlags == 0) {
-                                        ModFlags = method.ModFlags;
-                                        flags = method.flags;
-                                } else {
+                               if (ModFlags == 0) {
+                                       ModFlags = method.ModFlags;
+                                       flags = method.flags;
+                               } else {
+                                       if ((method.ModFlags & Modifiers.ABSTRACT) != 0 && (ModFlags & Modifiers.PRIVATE) != 0) {
+                                               Report.Error (442, Location, "{0}': abstract properties cannot have private accessors", GetSignatureForError (container));
+                                       }
+
                                        CheckModifiers (container, ModFlags);
                                        ModFlags |= (method.ModFlags & (~Modifiers.Accessibility));
+                                       ModFlags |= Modifiers.PROPERTY_CUSTOM;
                                        flags = Modifiers.MethodAttr (ModFlags);
                                        flags |= (method.flags & (~MethodAttributes.MemberAccessMask));
                                }
@@ -5793,6 +6114,13 @@ namespace Mono.CSharp {
 
                        }
 
+                       public bool HasCustomAccessModifier
+                       {
+                               get {
+                                       return (ModFlags & Modifiers.PROPERTY_CUSTOM) != 0;
+                               }
+                       }
+
                        public override Type[] ParameterTypes {
                                get {
                                        return TypeManager.NoTypes;
@@ -5818,27 +6146,32 @@ namespace Mono.CSharp {
                        }
                        
                        void CheckModifiers (TypeContainer container, int modflags)
-                        {
-                                int flags = 0;
-                                int mflags = method.ModFlags & Modifiers.Accessibility;
+                       {
+                               int flags = 0;
+                               int mflags = method.ModFlags & Modifiers.Accessibility;
 
-                                if ((mflags & Modifiers.PUBLIC) != 0) {
-                                        flags |= Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE;
-                                }
-                                else if ((mflags & Modifiers.PROTECTED) != 0) {
-                                        if ((mflags & Modifiers.INTERNAL) != 0)
-                                                flags |= Modifiers.PROTECTED | Modifiers.INTERNAL;
+                               if ((mflags & Modifiers.PUBLIC) != 0) {
+                                       flags |= Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE;
+                               }
+                               else if ((mflags & Modifiers.PROTECTED) != 0) {
+                                       if ((mflags & Modifiers.INTERNAL) != 0)
+                                               flags |= Modifiers.PROTECTED | Modifiers.INTERNAL;
 
-                                        flags |= Modifiers.PRIVATE;
-                                }
-                                else if ((mflags & Modifiers.INTERNAL) != 0)
-                                        flags |= Modifiers.PRIVATE;
+                                       flags |= Modifiers.PRIVATE;
+                               }
+                               else if ((mflags & Modifiers.INTERNAL) != 0)
+                                       flags |= Modifiers.PRIVATE;
 
-                                if ((mflags == modflags) || (modflags & (~flags)) != 0)
-                                        Report.Error (273, Location, "{0}: accessibility modifier must be more restrictive than the property or indexer",
-                                                       GetSignatureForError (container));
-                        }
+                               if ((mflags == modflags) || (modflags & (~flags)) != 0)
+                                       Report.Error (273, Location, "{0}: accessibility modifier must be more restrictive than the property or indexer",
+                                               GetSignatureForError (container));
+                       }
 
+                       public override bool MarkForDuplicationCheck ()
+                       {
+                               caching_flags |= Flags.TestMethodDuplication;
+                               return true;
+                       }
                }
 
 
@@ -5923,7 +6256,6 @@ namespace Mono.CSharp {
                        return TypeManager.CSharpSignature (PropertyBuilder, false);
                }
 
-
                protected override bool CheckForDuplications ()
                {
                        ArrayList ar = Parent.Indexers;
@@ -5952,33 +6284,33 @@ namespace Mono.CSharp {
                }
 
                // TODO: rename to Resolve......
-               protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+               protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
                {
-                       PropertyInfo parent_property = container.ParentCache.FindMemberToOverride (
+                       PropertyInfo base_property = container.BaseCache.FindMemberToOverride (
                                container.TypeBuilder, Name, ParameterTypes, true) as PropertyInfo;
   
-                       if (parent_property == null)
+                       if (base_property == null)
                                return null;
   
-                       parent_ret_type = parent_property.PropertyType;
-                       MethodInfo get_accessor = parent_property.GetGetMethod (true);
-                       MethodInfo set_accessor = parent_property.GetSetMethod (true);
+                       base_ret_type = base_property.PropertyType;
+                       MethodInfo get_accessor = base_property.GetGetMethod (true);
+                       MethodInfo set_accessor = base_property.GetSetMethod (true);
                        MethodAttributes get_accessor_access, set_accessor_access;
 
                        if ((ModFlags & Modifiers.OVERRIDE) != 0) {
                                if (Get != null && !Get.IsDummy && get_accessor == null) {
-                                       Report.SymbolRelatedToPreviousError (parent_property);
-                                       Report.Error (545, Location, "'{0}': cannot override because '{1}' does not have an overridable get accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (parent_property));
+                                       Report.SymbolRelatedToPreviousError (base_property);
+                                       Report.Error (545, Location, "'{0}': cannot override because '{1}' does not have an overridable get accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
                                }
 
                                if (Set != null && !Set.IsDummy && set_accessor == null) {
-                                       Report.SymbolRelatedToPreviousError (parent_property);
-                                       Report.Error (546, Location, "'{0}': cannot override because '{1}' does not have an overridable set accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (parent_property));
+                                       Report.SymbolRelatedToPreviousError (base_property);
+                                       Report.Error (546, Location, "'{0}': cannot override because '{1}' does not have an overridable set accessor", GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
                                }
                        }
                        
                        //
-                       // Check parent accessors access
+                       // Check base class accessors access
                        //
                        get_accessor_access = set_accessor_access = 0;
                        if ((ModFlags & Modifiers.NEW) == 0) {
@@ -5988,7 +6320,7 @@ namespace Mono.CSharp {
 
                                        if (!Get.IsDummy && !CheckAccessModifiers (get_flags & MethodAttributes.MemberAccessMask, get_accessor_access, get_accessor))
                                                Report.Error (507, Location, "'{0}' can't change the access modifiers when overriding inherited member '{1}'",
-                                                               GetSignatureForError (), TypeManager.GetFullNameSignature (parent_property));
+                                                               GetSignatureForError (), TypeManager.GetFullNameSignature (base_property));
                                }
 
                                if (set_accessor != null)  {
@@ -5997,7 +6329,7 @@ namespace Mono.CSharp {
 
                                        if (!Set.IsDummy && !CheckAccessModifiers (set_flags & MethodAttributes.MemberAccessMask, set_accessor_access, set_accessor))
                                                Report.Error (507, Location, "'{0}' can't change the access modifiers when overriding inherited member '{1}'",
-                                                               GetSignatureForError (container), TypeManager.GetFullNameSignature (parent_property));
+                                                               GetSignatureForError (container), TypeManager.GetFullNameSignature (base_property));
                                }
                        }
 
@@ -6034,15 +6366,24 @@ namespace Mono.CSharp {
                        return Get.IsDuplicateImplementation (mc) || Set.IsDuplicateImplementation (mc);
                }
 
-               protected override void UpdateMemberName ()
+               public override bool IsUsed
+               {
+                       get {
+                               if (IsExplicitImpl)
+                                       return true;
+
+                               return Get.IsUsed | Set.IsUsed;
+                       }
+               }
+
+               protected override void SetMemberName (MemberName new_name)
                {
-                       base.UpdateMemberName ();
+                       base.SetMemberName (new_name);
 
                        Get.UpdateName (this);
                        Set.UpdateName (this);
                }
 
-
                public override string[] ValidAttributeTargets {
                        get {
                                return attribute_targets;
@@ -6117,7 +6458,7 @@ namespace Mono.CSharp {
                                if ((ModFlags & Modifiers.METHOD_YIELDS) != 0){
                                        Iterator iterator = new Iterator (
                                                Parent, "get", MemberType,
-                                               TypeManager.NoTypes, Get.ParameterInfo,
+                                               Get.ParameterInfo,
                                                ModFlags, Get.Block, Location);
                                        
                                        if (!iterator.DefineIterator ())
@@ -6299,8 +6640,10 @@ namespace Mono.CSharp {
                
                public void SetUsed ()
                {
-                       if (my_event != null)
-                               my_event.status = (FieldBase.Status.ASSIGNED | FieldBase.Status.USED);
+                       if (my_event != null) {
+                               my_event.status = FieldBase.Status.ASSIGNED;
+                               my_event.SetMemberIsUsed ();
+                       }
                }
        }
        
@@ -6438,7 +6781,7 @@ namespace Mono.CSharp {
                        {
                                if (a.Target == AttributeTargets.Parameter) {
                                        if (param_attr == null)
-                                               param_attr = new ImplicitParameter (method_data.MethodBuilder);
+                                               param_attr = new ImplicitParameter (method_data.MethodBuilder, method.Location);
 
                                        param_attr.ApplyAttributeBuilder (a, cb);
                                        return;
@@ -6472,15 +6815,17 @@ namespace Mono.CSharp {
                        }
 
 
-                       public override void Emit (TypeContainer tc)
+                       protected override void EmitMethod (TypeContainer tc)
                        {
                                if (block != null) {
-                                       base.Emit (tc);
+                                       base.EmitMethod (tc);
                                        return;
                                }
 
+                               if ((method.ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
+                                       return;
+
                                ILGenerator ig = method_data.MethodBuilder.GetILGenerator ();
-                               EmitContext ec = CreateEmitContext (tc, ig);
                                FieldInfo field_info = (FieldInfo)method.FieldBuilder;
 
                                method_data.MethodBuilder.SetImplementationFlags (MethodImplAttributes.Synchronized);
@@ -6620,8 +6965,8 @@ namespace Mono.CSharp {
                        ec.InUnsafe = InUnsafe;
 
                        Parameter [] parms = new Parameter [1];
-                       parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null);
-                       Parameters parameters = new Parameters (parms, null, Location);
+                       parms [0] = new Parameter (Type, "value", Parameter.Modifier.NONE, null, Location);
+                       Parameters parameters = new Parameters (parms, null);
                        Type [] types = parameters.GetParameterInfo (ec);
                        InternalParameters ip = new InternalParameters (types, parameters);
 
@@ -6684,10 +7029,8 @@ namespace Mono.CSharp {
                                OptAttributes.Emit (ec, this);
                        }
 
-                       if (!IsInterface) {
-                               Add.Emit (Parent);
-                               Remove.Emit (Parent);
-                       }
+                       Add.Emit (Parent);
+                       Remove.Emit (Parent);
 
                        base.Emit ();
                }
@@ -6723,6 +7066,14 @@ namespace Mono.CSharp {
                        {
                        }
 
+                       // TODO: one GetSignatureForError is enough (reuse Parent member)
+                       public override string GetSignatureForError (TypeContainer tc)
+                       {
+                               string core = base.GetSignatureForError (tc);
+                               return core.Replace (TypeContainer.DefaultIndexerName, 
+                                       String.Format ("this[{0}]", TypeManager.CSharpName (ParameterTypes)));
+                       }
+
                        public override Type[] ParameterTypes {
                                get {
                                        return method.ParameterTypes;
@@ -6779,9 +7130,9 @@ namespace Mono.CSharp {
 
                                fixed_parms.CopyTo (tmp, 0);
                                tmp [fixed_parms.Length] = new Parameter (
-                                       method.Type, "value", Parameter.Modifier.NONE, null);
+                                       method.Type, "value", Parameter.Modifier.NONE, null, method.Location);
 
-                               Parameters set_formal_params = new Parameters (tmp, null, method.Location);
+                               Parameters set_formal_params = new Parameters (tmp, null);
                                Type [] types = set_formal_params.GetParameterInfo (ec);
                                
                                return new InternalParameters (types, set_formal_params);
@@ -6833,6 +7184,11 @@ namespace Mono.CSharp {
                        if (!base.Define ())
                                return false;
 
+                       if (MemberType == TypeManager.void_type) {
+                               Report.Error (620, Location, "Indexers cannot have void type");
+                               return false;
+                       }
+
                        if (OptAttributes != null) {
                                Attribute indexer_attr = OptAttributes.Search (TypeManager.indexer_name_type, ec);
                                if (indexer_attr != null) {
@@ -6843,7 +7199,7 @@ namespace Mono.CSharp {
 
                                        if (IsExplicitImpl) {
                                                Report.Error (415, indexer_attr.Location,
-                                                             "The 'IndexerName' attribute is valid only on an" +
+                                                             "The 'IndexerName' attribute is valid only on an " +
                                                              "indexer that is not an explicit interface member declaration");
                                                return false;
                                        }
@@ -6859,20 +7215,17 @@ namespace Mono.CSharp {
                                                              "The argument to the 'IndexerName' attribute must be a valid identifier");
                                                return false;
                                        }
-
-                                       UpdateMemberName ();
                                }
                        }
 
                        if (InterfaceType != null) {
-                               string parent_IndexerName = TypeManager.IndexerPropertyName (InterfaceType);
-                               if (parent_IndexerName != Name)
-                                       ShortName = parent_IndexerName;
-                                       UpdateMemberName ();
+                               string base_IndexerName = TypeManager.IndexerPropertyName (InterfaceType);
+                               if (base_IndexerName != Name)
+                                       ShortName = base_IndexerName;
                        }
 
-                       if (!Parent.AddToMemberContainer (this, true) ||
-                               !Parent.AddToMemberContainer (Get, true) || !Parent.AddToMemberContainer (Set, true))
+                       if (!Parent.AddToMemberContainer (this) ||
+                               !Parent.AddToMemberContainer (Get) || !Parent.AddToMemberContainer (Set))
                                return false;
 
                        if (!CheckBase ())
@@ -6951,6 +7304,13 @@ namespace Mono.CSharp {
                {
                        return String.Concat (tc.Name, ".this[", Parameters.FixedParameters [0].TypeName.ToString (), ']');
                }
+
+               public override bool MarkForDuplicationCheck ()
+               {
+                       caching_flags |= Flags.TestMethodDuplication;
+                       return true;
+               }
+
        }
 
        public class Operator : MethodCore, IIteratorContainer {
@@ -7066,6 +7426,11 @@ namespace Mono.CSharp {
                        if (!DoDefine ())
                                return false;
 
+                       if (MemberType == TypeManager.void_type) {
+                               Report.Error (590, Location, "User-defined operators cannot return void");
+                               return false;
+                       }
+
                        OperatorMethod = new Method (
                                Parent, Type, ModFlags, false, MemberName,
                                Parameters, OptAttributes, Location);
@@ -7202,7 +7567,7 @@ namespace Mono.CSharp {
                }
 
                // Operator cannot be override
-               protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+               protected override MethodInfo FindOutBaseMethod (TypeContainer container, ref Type base_ret_type)
                {
                        return null;
                }
@@ -7285,6 +7650,12 @@ namespace Mono.CSharp {
                        return ToString ();
                }
 
+               public override bool MarkForDuplicationCheck ()
+               {
+                       caching_flags |= Flags.TestMethodDuplication;
+                       return true;
+               }
+
                public override string ToString ()
                {
                        if (OperatorMethod == null)