2002-10-19 Ravi Pratap <ravi@ximian.com>
[mono.git] / mcs / mcs / class.cs
index af219faf6120a45d86304364004d201012f9f053..f7c8810c31a43eec822c010dc8605250c4a71d14 100755 (executable)
@@ -1,14 +1,35 @@
+
 //
 // class.cs: Class and Struct handlers
 //
-// Author: Miguel de Icaza (miguel@gnu.org)
+// Authors: Miguel de Icaza (miguel@gnu.org)
+//          Martin Baulig (martin@gnome.org)
 //
 // Licensed under the terms of the GNU GPL
 //
 // (C) 2001, 2002 Ximian, Inc (http://www.ximian.com)
 //
 //
-
+//  2002-10-11  Miguel de Icaza  <miguel@ximian.com>
+//
+//     * class.cs: Following the comment from 2002-09-26 to AddMethod, I
+//     have fixed a remaining problem: not every AddXXXX was adding a
+//     fully qualified name.  
+//
+//     Now everyone registers a fully qualified name in the DeclSpace as
+//     being defined instead of the partial name.  
+//
+//     Downsides: we are slower than we need to be due to the excess
+//     copies and the names being registered this way.  
+//
+//     The reason for this is that we currently depend (on the corlib
+//     bootstrap for instance) that types are fully qualified, because
+//     we dump all the types in the namespace, and we should really have
+//     types inserted into the proper namespace, so we can only store the
+//     basenames in the defined_names array.
+//
+//
+#define CACHE
 using System;
 using System.Collections;
 using System.Reflection;
@@ -21,7 +42,7 @@ namespace Mono.CSharp {
        /// <summary>
        ///   This is the base class for structs and classes.  
        /// </summary>
-       public class TypeContainer : DeclSpace {
+       public class TypeContainer : DeclSpace, IMemberContainer {
                // Holds a list of classes and structures
                ArrayList types;
 
@@ -105,6 +126,10 @@ namespace Mono.CSharp {
 
                // The interfaces we implement.
                Type [] ifaces;
+
+               // The parent member container and our member cache
+               IMemberContainer parent_container;
+               MemberCache member_cache;
                
                //
                // The indexer name for this class
@@ -130,16 +155,16 @@ namespace Mono.CSharp {
                public AdditionResult AddConstant (Const constant)
                {
                        AdditionResult res;
-                       string name = constant.Name;
+                       string basename = constant.Name;
 
-                       if ((res = IsValid (name)) != AdditionResult.Success)
+                       if ((res = IsValid (basename)) != AdditionResult.Success)
                                return res;
                        
                        if (constants == null)
                                constants = new ArrayList ();
 
                        constants.Add (constant);
-                       DefineName (name, constant);
+                       DefineName (Name + "." + basename, constant);
 
                        return AdditionResult.Success;
                }
@@ -147,16 +172,15 @@ namespace Mono.CSharp {
                public AdditionResult AddEnum (Mono.CSharp.Enum e)
                {
                        AdditionResult res;
-                       string name = e.Name;
 
-                       if ((res = IsValid (name)) != AdditionResult.Success)
+                       if ((res = IsValid (e.Basename)) != AdditionResult.Success)
                                return res;
 
                        if (enums == null)
                                enums = new ArrayList ();
 
                        enums.Add (e);
-                       DefineName (name, e);
+                       DefineName (e.Name, e);
 
                        return AdditionResult.Success;
                }
@@ -164,13 +188,11 @@ namespace Mono.CSharp {
                public AdditionResult AddClass (Class c)
                {
                        AdditionResult res;
-                       string name = c.Name;
-
 
-                       if ((res = IsValid (name)) != AdditionResult.Success)
+                       if ((res = IsValid (c.Basename)) != AdditionResult.Success)
                                return res;
 
-                       DefineName (name, c);
+                       DefineName (c.Name, c);
                        types.Add (c);
 
                        return AdditionResult.Success;
@@ -179,12 +201,11 @@ namespace Mono.CSharp {
                public AdditionResult AddStruct (Struct s)
                {
                        AdditionResult res;
-                       string name = s.Name;
                        
-                       if ((res = IsValid (name)) != AdditionResult.Success)
+                       if ((res = IsValid (s.Basename)) != AdditionResult.Success)
                                return res;
 
-                       DefineName (name, s);
+                       DefineName (s.Name, s);
                        types.Add (s);
 
                        return AdditionResult.Success;
@@ -193,15 +214,14 @@ namespace Mono.CSharp {
                public AdditionResult AddDelegate (Delegate d)
                {
                        AdditionResult res;
-                       string name = d.Name;
 
-                       if ((res = IsValid (name)) != AdditionResult.Success)
+                       if ((res = IsValid (d.Basename)) != AdditionResult.Success)
                                return res;
 
                        if (delegates == null)
                                delegates = new ArrayList ();
                        
-                       DefineName (name, d);
+                       DefineName (d.Name, d);
                        delegates.Add (d);
 
                        return AdditionResult.Success;
@@ -209,13 +229,15 @@ namespace Mono.CSharp {
 
                public AdditionResult AddMethod (Method method)
                {
-                       string name = method.Name;
-                       Object value = defined_names [name];
-                       
+                       string basename = method.Name;
+                       string fullname = Name + "." + basename;
+
+                       Object value = defined_names [fullname];
+
                        if (value != null && (!(value is Method)))
                                return AdditionResult.NameExists;
 
-                       if (name == Basename)
+                       if (basename == Basename)
                                return AdditionResult.EnclosingClash;
 
                        if (methods == null)
@@ -226,8 +248,8 @@ namespace Mono.CSharp {
                        else 
                                methods.Add (method);
                        
-                       if (value != null)
-                               DefineName (name, method);
+                       if (value == null)
+                               DefineName (fullname, method);
 
                        return AdditionResult.Success;
                }
@@ -267,15 +289,14 @@ namespace Mono.CSharp {
                public AdditionResult AddInterface (Interface iface)
                {
                        AdditionResult res;
-                       string name = iface.Name;
 
-                       if ((res = IsValid (name)) != AdditionResult.Success)
+                       if ((res = IsValid (iface.Basename)) != AdditionResult.Success)
                                return res;
                        
                        if (interfaces == null)
                                interfaces = new ArrayList ();
                        interfaces.Add (iface);
-                       DefineName (name, iface);
+                       DefineName (iface.Name, iface);
                        
                        return AdditionResult.Success;
                }
@@ -283,9 +304,9 @@ namespace Mono.CSharp {
                public AdditionResult AddField (Field field)
                {
                        AdditionResult res;
-                       string name = field.Name;
+                       string basename = field.Name;
 
-                       if ((res = IsValid (name)) != AdditionResult.Success)
+                       if ((res = IsValid (basename)) != AdditionResult.Success)
                                return res;
                        
                        if (fields == null)
@@ -293,7 +314,7 @@ namespace Mono.CSharp {
                        
                        fields.Add (field);
                        
-                       if (field.Initializer != null){
+                       if (field.HasInitializer){
                                if ((field.ModFlags & Modifiers.STATIC) != 0){
                                        if (initialized_static_fields == null)
                                                initialized_static_fields = new ArrayList ();
@@ -316,16 +337,16 @@ namespace Mono.CSharp {
                        if ((field.ModFlags & Modifiers.STATIC) == 0)
                                have_nonstatic_fields = true;
 
-                       DefineName (name, field);
+                       DefineName (Name + "." + basename, field);
                        return AdditionResult.Success;
                }
 
                public AdditionResult AddProperty (Property prop)
                {
                        AdditionResult res;
-                       string name = prop.Name;
+                       string basename = prop.Name;
 
-                       if ((res = IsValid (name)) != AdditionResult.Success)
+                       if ((res = IsValid (basename)) != AdditionResult.Success)
                                return res;
 
                        if (properties == null)
@@ -335,7 +356,7 @@ namespace Mono.CSharp {
                                properties.Insert (0, prop);
                        else
                                properties.Add (prop);
-                       DefineName (name, prop);
+                       DefineName (Name + "." + basename, prop);
 
                        return AdditionResult.Success;
                }
@@ -343,16 +364,16 @@ namespace Mono.CSharp {
                public AdditionResult AddEvent (Event e)
                {
                        AdditionResult res;
-                       string name = e.Name;
+                       string basename = e.Name;
 
-                       if ((res = IsValid (name)) != AdditionResult.Success)
+                       if ((res = IsValid (basename)) != AdditionResult.Success)
                                return res;
 
                        if (events == null)
                                events = new ArrayList ();
                        
                        events.Add (e);
-                       DefineName (name, e);
+                       DefineName (Name + "." + basename, e);
 
                        return AdditionResult.Success;
                }
@@ -517,16 +538,11 @@ namespace Mono.CSharp {
 
                        if (fields == null)
                                return true;
-                       
-                       foreach (Field f in fields){
-                               Object init = f.Initializer;
 
-                               Expression e;
-                               if (init is Expression)
-                                       e = (Expression) init;
-                               else {
-                                       e = new ArrayCreation (f.Type, "", (ArrayList)init, f.Location);
-                               }
+                       foreach (Field f in fields){
+                               Expression e = f.GetInitializerExpression (ec);
+                               if (e == null)
+                                       return false;
 
                                Location l = f.Location;
                                FieldExpr fe = new FieldExpr (f.FieldBuilder, l);
@@ -543,7 +559,7 @@ namespace Mono.CSharp {
                                        throw new Exception ("Assign.Resolve returned a non ExpressionStatement");
                                }
                        }
-                       
+
                        return true;
                }
                
@@ -555,9 +571,11 @@ namespace Mono.CSharp {
                        Constructor c;
                        int mods = 0;
 
-                       c = new Constructor (Basename, Parameters.GetEmptyReadOnlyParameters (),
-                                            new ConstructorBaseInitializer (null, new Location (-1)),
-                                            new Location (-1));
+                       c = new Constructor (Basename, Parameters.EmptyReadOnlyParameters,
+                                            new ConstructorBaseInitializer (
+                                                    null, Parameters.EmptyReadOnlyParameters,
+                                                    Location.Null),
+                                            Location.Null);
                        
                        if (is_static)
                                mods = Modifiers.STATIC;
@@ -653,6 +671,13 @@ namespace Mono.CSharp {
                                        start = 0;
                                }
 
+                               if (!AsAccessible (parent, ModFlags))
+                                       Report.Error (60, Location,
+                                                     "Inconsistent accessibility: base class `" +
+                                                     TypeManager.CSharpName (parent) + "' is less " +
+                                                     "accessible than class `" +
+                                                     Name + "'");
+
                        } else {
                                start = 0;
                        }
@@ -706,7 +731,7 @@ namespace Mono.CSharp {
                                                return null;
                                        }
                                }
-                               
+
                                ifaces [j] = t;
                        }
 
@@ -762,46 +787,25 @@ namespace Mono.CSharp {
                        // if (parent_builder is ModuleBuilder) {
                        if (IsTopLevel){
                                ModuleBuilder builder = CodeGen.ModuleBuilder;
+                               TypeBuilder = builder.DefineType (
+                                       Name, type_attributes, parent, ifaces);
                                
-                               //
-                               // Structs with no fields need to have a ".size 1"
-                               // appended
-                               //
-
-                               if (!is_class && !have_nonstatic_fields)
-                                       TypeBuilder = builder.DefineType (Name,
-                                                                         type_attributes,
-                                                                         parent, 
-                                                                         PackingSize.Unspecified, 1);
-                               else
-                               //
-                               // classes or structs with fields
-                               //
-                                       TypeBuilder = builder.DefineType (Name,
-                                                                         type_attributes,
-                                                                         parent,
-                                                                         ifaces);
                        } else {
                                TypeBuilder builder = Parent.TypeBuilder;
+                               TypeBuilder = builder.DefineNestedType (
+                                       Basename, type_attributes, parent, ifaces);
+                       }
                                
-                               //
-                               // Structs with no fields need to have a ".size 1"
-                               // appended
-                               //
-                               if (!is_class && !have_nonstatic_fields)
-                                       TypeBuilder = builder.DefineNestedType (Basename,
-                                                                               type_attributes,
-                                                                               parent, 
-                                                                               PackingSize.Unspecified);
-                               else {
-                                       //
-                                       // classes or structs with fields
-                                       //
-                                       TypeBuilder = builder.DefineNestedType (Basename,
-                                                                               type_attributes,
-                                                                               parent,
-                                                                               ifaces);
-                               }
+                       //
+                       // 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 (!is_class && !have_nonstatic_fields){
+                               TypeBuilder.DefineField ("$PRIVATE$", TypeManager.byte_type,
+                                                        FieldAttributes.Private);
                        }
 
                        // add interfaces that were not added at type creation (weird API issue)
@@ -942,7 +946,7 @@ namespace Mono.CSharp {
                        IndexerName = class_indexer_name;
                }
 
-               static void Report1530 (Location loc)
+               static void Error_KeywordNotAllowed (Location loc)
                {
                        Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
                }
@@ -950,16 +954,16 @@ namespace Mono.CSharp {
                /// <summary>
                ///   Populates our TypeBuilder with fields and methods
                /// </summary>
-               public override bool Define (TypeContainer parent)
+               public override bool DefineMembers (TypeContainer parent)
                {
                        MemberInfo [] defined_names = null;
 
                        if (interface_order != null){
                                foreach (Interface iface in interface_order)
                                        if ((iface.ModFlags & Modifiers.NEW) == 0)
-                                               iface.Define (this);
+                                               iface.DefineMembers (this);
                                        else
-                                               Report1530 (iface.Location);
+                                               Error_KeywordNotAllowed (iface.Location);
                        }
 
                        if (RootContext.WarningLevel > 1){
@@ -971,7 +975,7 @@ namespace Mono.CSharp {
                                //
                                ptype = TypeBuilder.BaseType;
                                if (ptype != null){
-                                       defined_names = FindMembers (
+                                       defined_names = (MemberInfo []) FindMembers (
                                                ptype, MemberTypes.All & ~MemberTypes.Constructor,
                                                BindingFlags.Public | BindingFlags.Instance |
                                                BindingFlags.Static, null, null);
@@ -1035,15 +1039,36 @@ namespace Mono.CSharp {
                        } else
                                IndexerName = "Item";
 
-                       if (operators != null)
+                       if (operators != null){
                                DefineMembers (operators, null);
 
+                               CheckPairedOperators ();
+                       }
+
                        if (enums != null)
                                DefineMembers (enums, defined_names);
                        
                        if (delegates != null)
                                DefineMembers (delegates, defined_names);
 
+#if CACHE
+                       if (TypeBuilder.BaseType != null)
+                               parent_container = TypeManager.LookupMemberContainer (TypeBuilder.BaseType);
+
+                       member_cache = new MemberCache (this);
+#endif
+
+                       return true;
+               }
+
+               public override bool Define (TypeContainer parent)
+               {
+                       if (interface_order != null){
+                               foreach (Interface iface in interface_order)
+                                       if ((iface.ModFlags & Modifiers.NEW) == 0)
+                                               iface.Define (this);
+                       }
+
                        return true;
                }
 
@@ -1092,11 +1117,35 @@ namespace Mono.CSharp {
                //
                // Since the whole process is a no-op, it is fine to check for null here.
                //
-               public MemberInfo [] FindMembers (MemberTypes mt, BindingFlags bf,
-                                                 MemberFilter filter, object criteria)
+               public override MemberList FindMembers (MemberTypes mt, BindingFlags bf,
+                                                       MemberFilter filter, object criteria)
                {
                        ArrayList members = new ArrayList ();
-                       bool priv = (bf & BindingFlags.NonPublic) != 0;
+
+                       int modflags = 0;
+                       if ((bf & BindingFlags.Public) != 0)
+                               modflags |= Modifiers.PUBLIC | Modifiers.PROTECTED |
+                                       Modifiers.INTERNAL;
+                       if ((bf & BindingFlags.NonPublic) != 0)
+                               modflags |= Modifiers.PRIVATE;
+
+                       int static_mask = 0, static_flags = 0;
+                       switch (bf & (BindingFlags.Static | BindingFlags.Instance)) {
+                       case BindingFlags.Static:
+                               static_mask = static_flags = Modifiers.STATIC;
+                               break;
+
+                       case BindingFlags.Instance:
+                               static_mask = Modifiers.STATIC;
+                               static_flags = 0;
+                               break;
+
+                       default:
+                               static_mask = static_flags = 0;
+                               break;
+                       }
+
+                       Timer.StartTimer (TimerType.TcFindMembers);
 
                        if (filter == null)
                                filter = accepting_filter; 
@@ -1104,9 +1153,10 @@ namespace Mono.CSharp {
                        if ((mt & MemberTypes.Field) != 0) {
                                if (fields != null) {
                                        foreach (Field f in fields) {
-                                               if ((f.ModFlags & Modifiers.PRIVATE) != 0)
-                                                       if (!priv)
-                                                               continue;
+                                               if ((f.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((f.ModFlags & static_mask) != static_flags)
+                                                       continue;
 
                                                FieldBuilder fb = f.FieldBuilder;
                                                if (fb != null && filter (fb, criteria) == true)
@@ -1116,10 +1166,11 @@ namespace Mono.CSharp {
 
                                if (constants != null) {
                                        foreach (Const con in constants) {
-                                               if ((con.ModFlags & Modifiers.PRIVATE) != 0)
-                                                       if (!priv)
-                                                               continue;
-                                               
+                                               if ((con.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((con.ModFlags & static_mask) != static_flags)
+                                                       continue;
+
                                                FieldBuilder fb = con.FieldBuilder;
                                                if (fb != null && filter (fb, criteria) == true)
                                                        members.Add (fb);
@@ -1130,9 +1181,10 @@ namespace Mono.CSharp {
                        if ((mt & MemberTypes.Method) != 0) {
                                if (methods != null) {
                                        foreach (Method m in methods) {
-                                               if ((m.ModFlags & Modifiers.PRIVATE) != 0)
-                                                       if (!priv)
-                                                               continue;
+                                               if ((m.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((m.ModFlags & static_mask) != static_flags)
+                                                       continue;
                                                
                                                MethodBuilder mb = m.MethodBuilder;
 
@@ -1143,9 +1195,10 @@ namespace Mono.CSharp {
 
                                if (operators != null){
                                        foreach (Operator o in operators) {
-                                               if ((o.ModFlags & Modifiers.PRIVATE) != 0)
-                                                       if (!priv)
-                                                               continue;
+                                               if ((o.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((o.ModFlags & static_mask) != static_flags)
+                                                       continue;
                                                
                                                MethodBuilder ob = o.OperatorMethodBuilder;
                                                if (ob != null && filter (ob, criteria) == true)
@@ -1155,9 +1208,10 @@ namespace Mono.CSharp {
 
                                if (properties != null){
                                        foreach (Property p in properties){
-                                               if ((p.ModFlags & Modifiers.PRIVATE) != 0)
-                                                       if (!priv)
-                                                               continue;
+                                               if ((p.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((p.ModFlags & static_mask) != static_flags)
+                                                       continue;
                                                
                                                MethodBuilder b;
 
@@ -1170,14 +1224,34 @@ namespace Mono.CSharp {
                                                        members.Add (b);
                                        }
                                }
+
+                               if (indexers != null){
+                                       foreach (Indexer ix in indexers){
+                                               if ((ix.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((ix.ModFlags & static_mask) != static_flags)
+                                                       continue;
+                                               
+                                               MethodBuilder b;
+
+                                               b = ix.GetBuilder;
+                                               if (b != null && filter (b, criteria) == true)
+                                                       members.Add (b);
+
+                                               b = ix.SetBuilder;
+                                               if (b != null && filter (b, criteria) == true)
+                                                       members.Add (b);
+                                       }
+                               }
                        }
 
                        if ((mt & MemberTypes.Event) != 0) {
                                if (events != null)
                                        foreach (Event e in events) {
-                                               if ((e.ModFlags & Modifiers.PRIVATE) != 0)
-                                                       if (!priv)
-                                                               continue;
+                                               if ((e.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((e.ModFlags & static_mask) != static_flags)
+                                                       continue;
 
                                                MemberInfo eb = e.EventBuilder;
                                                if (eb != null && filter (eb, criteria) == true)
@@ -1188,9 +1262,10 @@ namespace Mono.CSharp {
                        if ((mt & MemberTypes.Property) != 0){
                                if (properties != null)
                                        foreach (Property p in properties) {
-                                               if ((p.ModFlags & Modifiers.PRIVATE) != 0)
-                                                       if (!priv)
-                                                               continue;
+                                               if ((p.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((p.ModFlags & static_mask) != static_flags)
+                                                       continue;
 
                                                MemberInfo pb = p.PropertyBuilder;
                                                if (pb != null && filter (pb, criteria) == true) {
@@ -1200,9 +1275,10 @@ namespace Mono.CSharp {
 
                                if (indexers != null)
                                        foreach (Indexer ix in indexers) {
-                                               if ((ix.ModFlags & Modifiers.PRIVATE) != 0)
-                                                       if (!priv)
-                                                               continue;
+                                               if ((ix.ModFlags & modflags) == 0)
+                                                       continue;
+                                               if ((ix.ModFlags & static_mask) != static_flags)
+                                                       continue;
 
                                                MemberInfo ib = ix.PropertyBuilder;
                                                if (ib != null && filter (ib, criteria) == true) {
@@ -1214,8 +1290,10 @@ namespace Mono.CSharp {
                        if ((mt & MemberTypes.NestedType) != 0) {
                                if (types != null){
                                        foreach (TypeContainer t in types) {
-                                               TypeBuilder tb = t.TypeBuilder;
+                                               if ((t.ModFlags & modflags) == 0)
+                                                       continue;
 
+                                               TypeBuilder tb = t.TypeBuilder;
                                                if (tb != null && (filter (tb, criteria) == true))
                                                                members.Add (tb);
                                        }
@@ -1223,8 +1301,10 @@ namespace Mono.CSharp {
 
                                if (enums != null){
                                        foreach (Enum en in enums){
-                                               TypeBuilder tb = en.TypeBuilder;
+                                               if ((en.ModFlags & modflags) == 0)
+                                                       continue;
 
+                                               TypeBuilder tb = en.TypeBuilder;
                                                if (tb != null && (filter (tb, criteria) == true))
                                                        members.Add (tb);
                                        }
@@ -1232,8 +1312,21 @@ namespace Mono.CSharp {
                                
                                if (delegates != null){
                                        foreach (Delegate d in delegates){
+                                               if ((d.ModFlags & modflags) == 0)
+                                                       continue;
+
                                                TypeBuilder tb = d.TypeBuilder;
-                                               
+                                               if (tb != null && (filter (tb, criteria) == true))
+                                                       members.Add (tb);
+                                       }
+                               }
+
+                               if (interfaces != null){
+                                       foreach (Interface iface in interfaces){
+                                               if ((iface.ModFlags & modflags) == 0)
+                                                       continue;
+
+                                               TypeBuilder tb = iface.TypeBuilder;
                                                if (tb != null && (filter (tb, criteria) == true))
                                                        members.Add (tb);
                                        }
@@ -1241,17 +1334,16 @@ namespace Mono.CSharp {
                        }
 
                        if ((mt & MemberTypes.Constructor) != 0){
-                               if (instance_constructors != null){
+                               if (((bf & BindingFlags.Instance) != 0) && (instance_constructors != null)){
                                        foreach (Constructor c in instance_constructors){
                                                ConstructorBuilder cb = c.ConstructorBuilder;
-
                                                if (cb != null)
                                                        if (filter (cb, criteria) == true)
                                                                members.Add (cb);
                                        }
                                }
 
-                               if (default_static_constructor != null){
+                               if (((bf & BindingFlags.Static) != 0) && (default_static_constructor != null)){
                                        ConstructorBuilder cb =
                                                default_static_constructor.ConstructorBuilder;
                                        
@@ -1265,34 +1357,30 @@ namespace Mono.CSharp {
                        // Lookup members in parent if requested.
                        //
                        if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
-                               MemberInfo [] mi;
-
-                               mi = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
-                               if (mi != null)
-                                       members.AddRange (mi);
-                       }
-                       
-                       int count = members.Count;
-                       if (count > 0){
-                               MemberInfo [] mi = new MemberInfo [count];
-                               members.CopyTo (mi);
-                               return mi;
+                               MemberList list = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
+                               members.AddRange (list);
                        }
 
-                       return null;
+                       Timer.StopTimer (TimerType.TcFindMembers);
+
+                       return new MemberList (members);
                }
 
-               
+               public override MemberCache MemberCache {
+                       get {
+                               return member_cache;
+                       }
+               }
 
-               public static MemberInfo [] FindMembers (Type t, MemberTypes mt, BindingFlags bf,
-                                                        MemberFilter filter, object criteria)
+               public static MemberList FindMembers (Type t, MemberTypes mt, BindingFlags bf,
+                                                     MemberFilter filter, object criteria)
                {
                        TypeContainer tc = TypeManager.LookupTypeContainer (t);
 
                        if (tc != null)
                                return tc.FindMembers (mt, bf, filter, criteria);
                        else
-                               return t.FindMembers (mt, bf, filter, criteria);
+                               return new MemberList (t.FindMembers (mt, bf, filter, criteria));
                }
 
                //
@@ -1440,7 +1528,7 @@ namespace Mono.CSharp {
 
                        if (Delegates != null)
                                foreach (Delegate d in Delegates)
-                                       d.CloseDelegate ();
+                                       d.CloseType ();
                }
 
                public string MakeName (string n)
@@ -1553,13 +1641,103 @@ namespace Mono.CSharp {
                        return ok;
                }
 
+               // Access level of a type.
+               enum AccessLevel {
+                       Public                  = 0,
+                       ProtectedInternal       = 1,
+                       Internal                = 2,
+                       Protected               = 3,
+                       Private                 = 4
+               }
+
+               // Check whether `flags' denotes a more restricted access than `level'
+               // and return the new level.
+               static AccessLevel CheckAccessLevel (AccessLevel level, int flags)
+               {
+                       AccessLevel old_level = level;
+
+                       if ((flags & Modifiers.INTERNAL) != 0) {
+                               if ((flags & Modifiers.PROTECTED) != 0) {
+                                       if ((int) level < (int) AccessLevel.ProtectedInternal)
+                                               level = AccessLevel.ProtectedInternal;
+                               } else {
+                                       if ((int) level < (int) AccessLevel.Internal)
+                                               level = AccessLevel.Internal;
+                               }
+                       } else if ((flags & Modifiers.PROTECTED) != 0) {
+                               if ((int) level < (int) AccessLevel.Protected)
+                                       level = AccessLevel.Protected;
+                       } else if ((flags & Modifiers.PRIVATE) != 0)
+                               level = AccessLevel.Private;
+
+                       return level;
+               }
+
+               // Return the access level for a new member which is defined in the current
+               // TypeContainer with access modifiers `flags'.
+               AccessLevel GetAccessLevel (int flags)
+               {
+                       if ((flags & Modifiers.PRIVATE) != 0)
+                               return AccessLevel.Private;
+
+                       AccessLevel level;
+                       if (!IsTopLevel && (Parent != null))
+                               level = Parent.GetAccessLevel (flags);
+                       else
+                               level = AccessLevel.Public;
+
+                       return CheckAccessLevel (CheckAccessLevel (level, flags), ModFlags);
+               }
+
+               // Return the access level for type `t', but don't give more access than `flags'.
+               static AccessLevel GetAccessLevel (Type t, int flags)
+               {
+                       if (((flags & Modifiers.PRIVATE) != 0) || t.IsNestedPrivate)
+                               return AccessLevel.Private;
+
+                       AccessLevel level;
+                       if (TypeManager.IsBuiltinType (t))
+                               return AccessLevel.Public;
+                       else if ((t.DeclaringType != null) && (t != t.DeclaringType))
+                               level = GetAccessLevel (t.DeclaringType, flags);
+                       else {
+                               level = CheckAccessLevel (AccessLevel.Public, flags);
+                       }
+
+                       if (t.IsNestedPublic)
+                               return level;
+
+                       if (t.IsNestedAssembly || t.IsNotPublic) {
+                               if ((int) level < (int) AccessLevel.Internal)
+                                       level = AccessLevel.Internal;
+                       }
+
+                       if (t.IsNestedFamily) {
+                               if ((int) level < (int) AccessLevel.Protected)
+                                       level = AccessLevel.Protected;
+                       }
+
+                       if (t.IsNestedFamORAssem) {
+                               if ((int) level < (int) AccessLevel.ProtectedInternal)
+                                       level = AccessLevel.ProtectedInternal;
+                       }
+
+                       return level;
+               }
+
                //
-               // Returns true if `type' is as accessible as the flags `flags'
-               // given for this member
+               // Returns true if `parent' is as accessible as the flags `flags'
+               // given for this member.
                //
-               static public bool AsAccessible (Type type, int flags)
+               public bool AsAccessible (Type parent, int flags)
                {
-                       return true;
+                       while (parent.IsArray || parent.IsPointer || parent.IsByRef)
+                               parent = parent.GetElementType ();
+
+                       AccessLevel level = GetAccessLevel (flags);
+                       AccessLevel level2 = GetAccessLevel (parent, flags);
+
+                       return (int) level >= (int) level2;
                }
 
                Hashtable builder_and_args;
@@ -1601,6 +1779,170 @@ namespace Mono.CSharp {
                {
                        Report.Error (539, loc, "Explicit implementation: `" + name + "' is not a member of the interface");
                }
+
+               //
+               // IMemberContainer
+               //
+
+               string IMemberContainer.Name {
+                       get {
+                               return Name;
+                       }
+               }
+
+               Type IMemberContainer.Type {
+                       get {
+                               return TypeBuilder;
+                       }
+               }
+
+               IMemberContainer IMemberContainer.Parent {
+                       get {
+                               return parent_container;
+                       }
+               }
+
+               MemberCache IMemberContainer.MemberCache {
+                       get {
+                               return member_cache;
+                       }
+               }
+
+               bool IMemberContainer.IsInterface {
+                       get {
+                               return false;
+                       }
+               }
+
+               MemberList IMemberContainer.GetMembers (MemberTypes mt, BindingFlags bf)
+               {
+                       return FindMembers (mt, bf | BindingFlags.DeclaredOnly, null, null);
+               }
+
+               //
+               // Operator pair checking
+               //
+
+               class OperatorEntry {
+                       public int flags;
+                       public Type ret_type;
+                       public Type type1, type2;
+                       public Operator op;
+                       public Operator.OpType ot;
+                       
+                       public OperatorEntry (int f, Operator o)
+                       {
+                               flags = f;
+
+                               ret_type = o.OperatorMethod.GetReturnType ();
+                               Type [] pt = o.OperatorMethod.ParameterTypes;
+                               type1 = pt [0];
+                               type2 = pt [1];
+                               op = o;
+                               ot = o.OperatorType;
+                       }
+
+                       public override int GetHashCode ()
+                       {       
+                               return ret_type.GetHashCode ();
+                       }
+
+                       public override bool Equals (object o)
+                       {
+                               OperatorEntry other = (OperatorEntry) o;
+
+                               if (other.ret_type != ret_type)
+                                       return false;
+                               if (other.type1 != type1)
+                                       return false;
+                               if (other.type2 != type2)
+                                       return false;
+                               return true;
+                       }
+               }
+                               
+               //
+               // Checks that some operators come in pairs:
+               //  == and !=
+               // > and <
+               // >= and <=
+               //
+               // They are matched based on the return type and the argument types
+               //
+               void CheckPairedOperators ()
+               {
+                       Hashtable pairs = new Hashtable (null, null);
+
+                       // Register all the operators we care about.
+                       foreach (Operator op in operators){
+                               int reg = 0;
+                               
+                               switch (op.OperatorType){
+                               case Operator.OpType.Equality:
+                                       reg = 1; break;
+                               case Operator.OpType.Inequality:
+                                       reg = 2; break;
+                                       
+                               case Operator.OpType.GreaterThan:
+                                       reg = 1; break;
+                               case Operator.OpType.LessThan:
+                                       reg = 2; break;
+                                       
+                               case Operator.OpType.GreaterThanOrEqual:
+                                       reg = 1; break;
+                               case Operator.OpType.LessThanOrEqual:
+                                       reg = 2; break;
+                               }
+                               if (reg == 0)
+                                       continue;
+
+                               OperatorEntry oe = new OperatorEntry (reg, op);
+
+                               object o = pairs [oe];
+                               if (o == null)
+                                       pairs [oe] = oe;
+                               else {
+                                       oe = (OperatorEntry) o;
+                                       oe.flags |= reg;
+                               }
+                       }
+
+                       //
+                       // Look for the mistakes.
+                       //
+                       foreach (DictionaryEntry de in pairs){
+                               OperatorEntry oe = (OperatorEntry) de.Key;
+
+                               if (oe.flags == 3)
+                                       continue;
+
+                               string s = "";
+                               switch (oe.ot){
+                               case Operator.OpType.Equality:
+                                       s = "!=";
+                                       break;
+                               case Operator.OpType.Inequality: 
+                                       s = "==";
+                                       break;
+                               case Operator.OpType.GreaterThan: 
+                                       s = "<";
+                                       break;
+                               case Operator.OpType.LessThan:
+                                       s = ">";
+                                       break;
+                               case Operator.OpType.GreaterThanOrEqual:
+                                       s = "<=";
+                                       break;
+                               case Operator.OpType.LessThanOrEqual:
+                                       s = ">=";
+                                       break;
+                               }
+                               Report.Error (216, oe.op.Location,
+                                             "The operator `" + oe.op + "' requires a matching operator `" + s + "' to also be defined");
+                       }
+               }
+               
+               
        }
 
        public class Class : TypeContainer {
@@ -1845,11 +2187,14 @@ namespace Mono.CSharp {
                // function.  Provides a nice cache.  (used between semantic analysis
                // and actual code generation
                //
-               public Type GetReturnType (TypeContainer parent)
+               public Type GetReturnType ()
                {
                        return MemberType;
                }
 
+               // Whether this is an operator method.
+               public bool IsOperator;
+
                 void DuplicateEntryPoint (MethodInfo b, Location location)
                 {
                         Report.Error (
@@ -1901,6 +2246,25 @@ namespace Mono.CSharp {
                        if (!DoDefineParameters (parent))
                                return false;
 
+                       MethodSignature ms = new MethodSignature (Name, null, ParameterTypes);
+                       if (!IsOperator) {
+                               MemberList mi_this;
+
+                               mi_this = TypeContainer.FindMembers (
+                                       parent.TypeBuilder, MemberTypes.Method,
+                                       BindingFlags.NonPublic | BindingFlags.Public |
+                                       BindingFlags.Static | BindingFlags.Instance |
+                                       BindingFlags.DeclaredOnly,
+                                       MethodSignature.method_signature_filter, ms);
+
+                               if (mi_this.Count > 0) {
+                                       Report.Error (111, Location, "Class `" + parent.Name + "' " +
+                                                     "already defines a member called `" + Name + "' " +
+                                                     "with the same parameter types");
+                                       return false;
+                               }
+                       }
+
                        //
                        // Verify if the parent has a type with the same name, and then
                        // check whether we have to create a new slot for it or not.
@@ -1909,8 +2273,7 @@ namespace Mono.CSharp {
 
                        // ptype is only null for System.Object while compiling corlib.
                        if (ptype != null){
-                               MethodSignature ms = new MethodSignature (Name, null, ParameterTypes);
-                               MemberInfo [] mi, mi_static, mi_instance;
+                               MemberList mi, mi_static, mi_instance;
 
                                mi_static = TypeContainer.FindMembers (
                                        ptype, MemberTypes.Method,
@@ -1923,18 +2286,33 @@ namespace Mono.CSharp {
                                        MethodSignature.inheritable_method_signature_filter,
                                        ms);
 
-                               if (mi_instance != null && mi_instance.Length > 0){
+                               if (mi_instance.Count > 0){
                                        mi = mi_instance;
-                               } else if (mi_static != null && mi_static.Length > 0)
+                               } else if (mi_static.Count > 0)
                                        mi = mi_static;
                                else
                                        mi = null;
 
-                               if (mi != null && mi.Length > 0){
-                                       if (!CheckMethodAgainstBase (parent, flags, (MethodInfo) mi [0])){
+                               if (mi != null && mi.Count > 0){
+                                       parent_method = (MethodInfo) mi [0];
+                                       string name = parent_method.DeclaringType.Name + "." +
+                                               parent_method.Name;
+
+                                       if (!CheckMethodAgainstBase (parent, flags, parent_method, name))
                                                return false;
+
+                                       if ((ModFlags & Modifiers.NEW) == 0) {
+                                               Type parent_ret = TypeManager.TypeToCoreType (
+                                                       parent_method.ReturnType);
+
+                                               if (parent_ret != MemberType) {
+                                                       Report.Error (
+                                                               508, parent.MakeName (Name) + ": cannot " +
+                                                               "change return type when overriding " +
+                                                               "inherited member " + name);
+                                                       return false;
+                                               }
                                        }
-                                       parent_method = (MethodInfo) mi [0];
                                } else {
                                        if ((ModFlags & Modifiers.NEW) != 0)
                                                WarningNotHiding (parent);
@@ -1959,6 +2337,9 @@ namespace Mono.CSharp {
                        if (!DoDefine (parent))
                                return false;
 
+                       if (!CheckBase (parent))
+                               return false;
+
                        CallingConventions cc = GetCallingConvention (parent is Class);
 
                        MethodData = new MethodData (this, null, MemberType, ParameterTypes,
@@ -2004,12 +2385,15 @@ namespace Mono.CSharp {
        public abstract class ConstructorInitializer {
                ArrayList argument_list;
                ConstructorInfo parent_constructor;
-               Location location;
+               Parameters parameters;
+               Location loc;
                
-               public ConstructorInitializer (ArrayList argument_list, Location location)
+               public ConstructorInitializer (ArrayList argument_list, Parameters parameters,
+                                              Location loc)
                {
                        this.argument_list = argument_list;
-                       this.location = location;
+                       this.parameters = parameters;
+                       this.loc = loc;
                }
 
                public ArrayList Arguments {
@@ -2022,44 +2406,48 @@ namespace Mono.CSharp {
                {
                        Expression parent_constructor_group;
                        Type t;
-                       
+
+                       ec.CurrentBlock = new Block (null, true, parameters);
+
                        if (argument_list != null){
                                foreach (Argument a in argument_list){
-                                       if (!a.Resolve (ec, location))
+                                       if (!a.Resolve (ec, loc))
                                                return false;
                                }
                        }
 
+                       ec.CurrentBlock = null;
+
                        if (this is ConstructorBaseInitializer) {
                                if (ec.ContainerType.BaseType == null)
                                        return true;
 
                                t = ec.ContainerType.BaseType;
                                if (ec.ContainerType.IsValueType) {
-                                       Report.Error (522, location,
+                                       Report.Error (522, loc,
                                                "structs cannot call base class constructors");
                                        return false;
                                }
                        } else
                                t = ec.ContainerType;
-                       
+
                        parent_constructor_group = Expression.MemberLookup (
-                               ec, t, ".ctor", 
+                               ec, t, t, ".ctor", 
                                MemberTypes.Constructor,
                                BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly,
-                               location);
+                               loc);
                        
                        if (parent_constructor_group == null){
-                               Report.Error (1501, location,
+                               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, location);
+                               (MethodGroupExpr) parent_constructor_group, argument_list, loc);
                        
                        if (parent_constructor == null){
-                               Report.Error (1501, location,
+                               Report.Error (1501, loc,
                                       "Can not find a constructor for this argument list");
                                return false;
                        }
@@ -2069,23 +2457,25 @@ namespace Mono.CSharp {
 
                public void Emit (EmitContext ec)
                {
-                       if (parent_constructor != null)
-                               ec.ig.Emit (OpCodes.Ldarg_0);
-                       if (argument_list != null)
-                               Invocation.EmitArguments (ec, null, argument_list);
-                       if (parent_constructor != null)
-                               ec.ig.Emit (OpCodes.Call, parent_constructor);
+                       if (parent_constructor != null){
+                               if (ec.IsStatic)
+                                       Invocation.EmitCall (ec, true, true, null, parent_constructor, argument_list, loc);
+                               else
+                                       Invocation.EmitCall (ec, true, false, ec.This, parent_constructor, argument_list, loc);
+                       }
                }
        }
 
        public class ConstructorBaseInitializer : ConstructorInitializer {
-               public ConstructorBaseInitializer (ArrayList argument_list, Location l) : base (argument_list, l)
+               public ConstructorBaseInitializer (ArrayList argument_list, Parameters pars, Location l) :
+                       base (argument_list, pars, l)
                {
                }
        }
 
        public class ConstructorThisInitializer : ConstructorInitializer {
-               public ConstructorThisInitializer (ArrayList argument_list, Location l) : base (argument_list, l)
+               public ConstructorThisInitializer (ArrayList argument_list, Parameters pars, Location l) :
+                       base (argument_list, pars, l)
                {
                }
        }
@@ -2098,12 +2488,13 @@ namespace Mono.CSharp {
                // <summary>
                //   Modifiers allowed for a constructor.
                // </summary>
-               const int AllowedModifiers =
+               public const int AllowedModifiers =
                        Modifiers.PUBLIC |
                        Modifiers.PROTECTED |
                        Modifiers.INTERNAL |
                        Modifiers.STATIC |
                        Modifiers.UNSAFE |
+                       Modifiers.EXTERN |              
                        Modifiers.PRIVATE;
 
                //
@@ -2154,7 +2545,21 @@ namespace Mono.CSharp {
                                                "constructors");
                                        return false;
                                }
-                               ca |= MethodAttributes.Public | MethodAttributes.HideBySig;
+                               ca |= MethodAttributes.HideBySig;
+
+                               if ((ModFlags & Modifiers.PUBLIC) != 0)
+                                       ca |= MethodAttributes.Public;
+                               else if ((ModFlags & Modifiers.PROTECTED) != 0){
+                                       if ((ModFlags & Modifiers.INTERNAL) != 0)
+                                               ca |= MethodAttributes.FamORAssem;
+                                       else 
+                                               ca |= MethodAttributes.Family;
+                               } else if ((ModFlags & Modifiers.INTERNAL) != 0)
+                                       ca |= MethodAttributes.Assembly;
+                               else if (IsDefault ())
+                                       ca |= MethodAttributes.Public;
+                               else
+                                       ca |= MethodAttributes.Private;
                        }
 
                        ConstructorBuilder = parent.TypeBuilder.DefineConstructor (
@@ -2185,7 +2590,8 @@ namespace Mono.CSharp {
 
                        if ((ModFlags & Modifiers.STATIC) == 0){
                                if (parent is Class && Initializer == null)
-                                       Initializer = new ConstructorBaseInitializer (null, parent.Location);
+                                       Initializer = new ConstructorBaseInitializer (
+                                               null, Parameters.EmptyReadOnlyParameters, parent.Location);
 
 
                                //
@@ -2215,6 +2621,12 @@ namespace Mono.CSharp {
 
                        Attribute.ApplyAttributes (ec, ConstructorBuilder, this, OptAttributes, Location);
 
+                       // 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 is Struct) && ((ModFlags & Modifiers.STATIC) == 0) &&
+                           (Initializer == null))
+                               Block.AddThisVariable (parent, Location);
+
                        ec.EmitTopBlock (Block, ParameterInfo, Location);
                }
        }
@@ -2458,7 +2870,7 @@ namespace Mono.CSharp {
                        else
                                name = member.ShortName;
                        method_name = prefix + name;
-                               
+
                        if (parent.Pending != null){
                                if (member is Indexer)
                                        implementing = parent.Pending.IsInterfaceIndexer (
@@ -2516,7 +2928,7 @@ namespace Mono.CSharp {
                                //
                                if (implementing.DeclaringType.IsInterface)
                                        flags |= MethodAttributes.NewSlot;
-                               
+
                                flags |=
                                        MethodAttributes.Virtual |
                                        MethodAttributes.HideBySig;
@@ -2620,19 +3032,31 @@ namespace Mono.CSharp {
                                //
                                if ((modifiers & Modifiers.ABSTRACT) != 0)
                                        Report.Error (
-                                               500, "Abstract method `" +
+                                               500, Location, "Abstract method `" +
                                                TypeManager.CSharpSignature (builder) +
                                                "' can not have a body");
 
                                if ((modifiers & Modifiers.EXTERN) != 0)
                                        Report.Error (
-                                               179, "External method `" +
+                                               179, Location, "External method `" +
                                                TypeManager.CSharpSignature (builder) +
                                                "' can not have a body");
 
                                return;
                        }
 
+                       //
+                       // Methods must have a body unless they're extern or abstract
+                       //
+                       if (block == null) {
+                               Report.Error (
+                                       501, Location, "Method `" +
+                                       TypeManager.CSharpSignature (builder) +
+                                       "' must declare a body since it is not marked " +
+                                       "abstract or extern");
+                               return;
+                       }
+
                        //
                        // Handle destructors specially
                        //
@@ -2682,7 +3106,7 @@ namespace Mono.CSharp {
                        
                        if (ec.ContainerType.BaseType != null) {
                                Expression member_lookup = Expression.MemberLookup (
-                                       ec, ec.ContainerType.BaseType, "Finalize",
+                                       ec, ec.ContainerType.BaseType, ec.ContainerType.BaseType, "Finalize",
                                        MemberTypes.Method, Expression.AllBindingFlags, Location);
 
                                if (member_lookup != null){
@@ -2764,10 +3188,23 @@ namespace Mono.CSharp {
                        bool error = false;
 
                        foreach (Type partype in parameters){
-                               if (!TypeContainer.AsAccessible (partype, ModFlags))
-                                       error = true;
                                if (partype.IsPointer && !UnsafeOK (parent))
                                        error = true;
+
+                               if (parent.AsAccessible (partype, ModFlags))
+                                       continue;
+
+                               if (this is Indexer)
+                                       Report.Error (55, Location,
+                                                     "Inconsistent accessibility: parameter type `" +
+                                                     TypeManager.CSharpName (partype) + "' is less " +
+                                                     "accessible than indexer `" + Name + "'");
+                               else
+                                       Report.Error (51, Location,
+                                                     "Inconsistent accessibility: parameter type `" +
+                                                     TypeManager.CSharpName (partype) + "' is less " +
+                                                     "accessible than method `" + Name + "'");
+                               error = true;
                        }
 
                        return !error;
@@ -2789,15 +3226,33 @@ namespace Mono.CSharp {
                                return false;
 
                        // verify accessibility
-                       if (!TypeContainer.AsAccessible (MemberType, ModFlags))
+                       if (!parent.AsAccessible (MemberType, ModFlags)) {
+                               if (this is Property)
+                                       Report.Error (53, Location,
+                                                     "Inconsistent accessibility: property type `" +
+                                                     TypeManager.CSharpName (MemberType) + "' is less " +
+                                                     "accessible than property `" + Name + "'");
+                               else if (this is Indexer)
+                                       Report.Error (54, Location,
+                                                     "Inconsistent accessibility: indexer return type `" +
+                                                     TypeManager.CSharpName (MemberType) + "' is less " +
+                                                     "accessible than indexer `" + Name + "'");
+                               else if (this is Method)
+                                       Report.Error (50, Location,
+                                                     "Inconsistent accessibility: return type `" +
+                                                     TypeManager.CSharpName (MemberType) + "' is less " +
+                                                     "accessible than method `" + Name + "'");
+                               else
+                                       Report.Error (52, Location,
+                                                     "Inconsistent accessibility: field type `" +
+                                                     TypeManager.CSharpName (MemberType) + "' is less " +
+                                                     "accessible than field `" + Name + "'");
                                return false;
+                       }
 
                        if (MemberType.IsPointer && !UnsafeOK (parent))
                                return false;
                        
-                       if (!CheckBase (parent))
-                               return false;
-
                        //
                        // Check for explicit interface implementation
                        //
@@ -2834,7 +3289,6 @@ namespace Mono.CSharp {
        // their common bits.  This is also used to flag usage of the field
        //
        abstract public class FieldBase : MemberBase {
-               public readonly Object Initializer;
                public FieldBuilder  FieldBuilder;
                public Status status;
 
@@ -2848,7 +3302,45 @@ namespace Mono.CSharp {
                                     object init, Attributes attrs, Location loc)
                        : base (type, mod, allowed_mod, name, attrs, loc)
                {
-                       Initializer = init;
+                       this.init = init;
+               }
+
+               //
+               // Whether this field has an initializer.
+               //
+               public bool HasInitializer {
+                       get {
+                               return init != null;
+                       }
+               }
+
+               // Private.
+               readonly Object init;
+               Expression init_expr;
+               bool init_expr_initialized = false;
+
+               //
+               // Resolves and returns the field initializer.
+               //
+               public Expression GetInitializerExpression (EmitContext ec)
+               {
+                       if (init_expr_initialized)
+                               return init_expr;
+
+                       Expression e;
+                       if (init is Expression)
+                               e = (Expression) init;
+                       else
+                               e = new ArrayCreation (Type, "", (ArrayList)init, Location);
+
+                       ec.IsFieldInitializer = true;
+                       e = e.DoResolve (ec);
+                       ec.IsFieldInitializer = false;
+
+                       init_expr = e;
+                       init_expr_initialized = true;
+
+                       return init_expr;
                }
        }
 
@@ -2883,8 +3375,13 @@ namespace Mono.CSharp {
                        if (t == null)
                                return false;
 
-                       if (!TypeContainer.AsAccessible (t, ModFlags))
+                       if (!parent.AsAccessible (t, ModFlags)) {
+                               Report.Error (52, Location,
+                                             "Inconsistent accessibility: field type `" +
+                                             TypeManager.CSharpName (t) + "' is less " +
+                                             "accessible than field `" + Name + "'");
                                return false;
+                       }
 
                        if (t.IsPointer && !UnsafeOK (parent))
                                return false;
@@ -2894,9 +3391,7 @@ namespace Mono.CSharp {
 
                                // ptype is only null for System.Object while compiling corlib.
                                if (ptype != null){
-                                       MemberInfo [] mi;
-                                       
-                                       mi = TypeContainer.FindMembers (
+                                       TypeContainer.FindMembers (
                                                ptype, MemberTypes.Method,
                                                BindingFlags.Public |
                                                BindingFlags.Static | BindingFlags.Instance,
@@ -2926,7 +3421,17 @@ namespace Mono.CSharp {
                                        }
                                }
                        }
-                       
+
+                       FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
+
+                       if (parent is Struct && 
+                           ((fa & FieldAttributes.Static) == 0) &&
+                           t == parent.TypeBuilder &&
+                           !TypeManager.IsBuiltinType (t)){
+                               Report.Error (523, Location, "Struct member `" + parent.Name + "." + Name + 
+                                             "' causes a cycle in the structure layout");
+                               return false;
+                       }
                        FieldBuilder = parent.TypeBuilder.DefineField (
                                Name, t, Modifiers.FieldAttr (ModFlags));
 
@@ -2959,74 +3464,109 @@ namespace Mono.CSharp {
                        OptAttributes = attrs;
                }
        }
-                       
-       public class Property : MemberBase {
+
+       //
+       // Properties and Indexers both generate PropertyBuilders, we use this to share 
+       // their common bits.
+       //
+       abstract public class PropertyBase : MethodCore {
                public Accessor Get, Set;
                public PropertyBuilder PropertyBuilder;
                public MethodBuilder GetBuilder, SetBuilder;
                public MethodData GetData, SetData;
 
-               const int AllowedModifiers =
-                       Modifiers.NEW |
-                       Modifiers.PUBLIC |
-                       Modifiers.PROTECTED |
-                       Modifiers.INTERNAL |
-                       Modifiers.PRIVATE |
-                       Modifiers.STATIC |
-                       Modifiers.SEALED |
-                       Modifiers.OVERRIDE |
-                       Modifiers.ABSTRACT |
-                       Modifiers.UNSAFE |
-                       Modifiers.EXTERN |
-                       Modifiers.VIRTUAL;
+               protected EmitContext ec;
 
-               public Property (Expression type, string name, int mod_flags,
-                                Accessor get_block, Accessor set_block,
-                                Attributes attrs, Location loc)
-                       : base (type, mod_flags, AllowedModifiers, name, attrs, loc)
+               public PropertyBase (Expression type, string name, int mod_flags, int allowed_mod,
+                                    Parameters parameters, Accessor get_block, Accessor set_block,
+                                    Attributes attrs, Location loc)
+                       : base (type, mod_flags, allowed_mod, name, attrs, parameters, loc)
                {
                        Get = get_block;
                        Set = set_block;
                }
 
+               protected override bool DoDefine (TypeContainer parent)
+               {
+                       if (!base.DoDefine (parent))
+                               return false;
+
+                       ec = new EmitContext (parent, Location, null, MemberType, ModFlags);
+
+                       return true;
+               }
+
                //
                // Checks our base implementation if any
                //
                protected override bool CheckBase (TypeContainer parent)
                {
+                       // Check whether arguments were correct.
+                       if (!DoDefineParameters (parent))
+                               return false;
+
+                       if (IsExplicitImpl)
+                               return true;
+
+                       string report_name;
+                       MethodSignature ms, base_ms;
+                       if (this is Indexer) {
+                               string name, base_name;
+
+                               report_name = "this";
+                               name = TypeManager.IndexerPropertyName (parent.TypeBuilder);
+                               ms = new MethodSignature (name, null, ParameterTypes);
+                               base_name = TypeManager.IndexerPropertyName (parent.TypeBuilder.BaseType);
+                               base_ms = new MethodSignature (base_name, null, ParameterTypes);
+                       } else {
+                               report_name = Name;
+                               ms = base_ms = new MethodSignature (Name, null, ParameterTypes);
+                       }
+
+                       MemberList props_this;
+
+                       props_this = TypeContainer.FindMembers (
+                               parent.TypeBuilder, MemberTypes.Property,
+                               BindingFlags.NonPublic | BindingFlags.Public |
+                               BindingFlags.Static | BindingFlags.Instance |
+                               BindingFlags.DeclaredOnly,
+                               MethodSignature.method_signature_filter, ms);
+
+                       if (props_this.Count > 0) {
+                               Report.Error (111, Location, "Class `" + parent.Name + "' " +
+                                             "already defines a member called `" + report_name + "' " +
+                                             "with the same parameter types");
+                               return false;
+                       }
+
                        //
                        // Find properties with the same name on the base class
                        //
-
-                       MemberInfo [] props;
-                       MemberInfo [] props_static = TypeManager.MemberLookup (
-                               parent.TypeBuilder, 
-                               parent.TypeBuilder.BaseType,
-                               MemberTypes.Property, BindingFlags.Public | BindingFlags.Static,
-                               Name);
-
-                       MemberInfo [] props_instance = TypeManager.MemberLookup (
-                               parent.TypeBuilder, 
-                               parent.TypeBuilder.BaseType,
-                               MemberTypes.Property, BindingFlags.Public | BindingFlags.Instance,
-                               Name);
+                       MemberList props;
+                       MemberList props_static = TypeContainer.FindMembers (
+                               parent.TypeBuilder.BaseType, MemberTypes.Property,
+                               BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static,
+                               MethodSignature.inheritable_property_signature_filter, base_ms);
+
+                       MemberList props_instance = TypeContainer.FindMembers (
+                               parent.TypeBuilder.BaseType, MemberTypes.Property,
+                               BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance,
+                               MethodSignature.inheritable_property_signature_filter,
+                               base_ms);
 
                        //
                        // Find if we have anything
                        //
-                       if (props_static != null && props_static.Length > 0)
+                       if (props_static.Count > 0)
                                props = props_static;
-                       else if (props_instance != null && props_instance.Length > 0)
+                       else if (props_instance.Count > 0)
                                props = props_instance;
                        else
                                props = null;
 
                        //
                        // If we have something on the base.
-                       if (props != null && props.Length > 0){
-                               if (props.Length > 1)
-                                       throw new Exception ("Should not happen");
-                               
+                       if (props != null && props.Count > 0){
                                PropertyInfo pi = (PropertyInfo) props [0];
 
                                MethodInfo inherited_get = TypeManager.GetPropertyGetter (pi);
@@ -3035,36 +3575,95 @@ namespace Mono.CSharp {
                                MethodInfo reference = inherited_get == null ?
                                        inherited_set : inherited_get;
                                
-                               if (reference != null)
-                                       if (!CheckMethodAgainstBase (parent, flags, reference))
+                               if (reference != null) {
+                                       string name = reference.DeclaringType.Name + "." + report_name;
+
+                                       if (!CheckMethodAgainstBase (parent, flags, reference, name))
                                                return false;
-                               
+                               }
+
+                               if (((ModFlags & Modifiers.NEW) == 0) && (pi.PropertyType != MemberType)) {
+                                       Report.Error (508, parent.MakeName (Name) + ": cannot " +
+                                                     "change return type when overriding inherited " +
+                                                     "member `" + pi.DeclaringType + "." + pi.Name + "'");
+                                       return false;
+                               }
                        } else {
                                if ((ModFlags & Modifiers.NEW) != 0)
                                        WarningNotHiding (parent);
                                
                                if ((ModFlags & Modifiers.OVERRIDE) != 0){
-                                       Report.Error (115, Location,
-                                                     parent.MakeName (Name) +
-                                                     " no suitable properties found to override");
+                                       if (this is Indexer)
+                                               Report.Error (115, Location,
+                                                             parent.MakeName (Name) +
+                                                             " no suitable indexers found to override");
+                                       else
+                                               Report.Error (115, Location,
+                                                             parent.MakeName (Name) +
+                                                             " no suitable properties found to override");
                                        return false;
                                }
                        }
                        return true;
                }
 
+               public void Emit (TypeContainer tc)
+               {
+                       //
+                       // The PropertyBuilder can be null for explicit implementations, in that
+                       // case, we do not actually emit the ".property", so there is nowhere to
+                       // put the attribute
+                       //
+                       if (PropertyBuilder != null)
+                               Attribute.ApplyAttributes (ec, PropertyBuilder, this, OptAttributes, Location);
+
+                       if (GetData != null)
+                               GetData.Emit (tc, Get.Block, Get);
+
+                       if (SetData != null)
+                               SetData.Emit (tc, Set.Block, Set);
+               }
+       }
+                       
+       public class Property : PropertyBase {
+               const int AllowedModifiers =
+                       Modifiers.NEW |
+                       Modifiers.PUBLIC |
+                       Modifiers.PROTECTED |
+                       Modifiers.INTERNAL |
+                       Modifiers.PRIVATE |
+                       Modifiers.STATIC |
+                       Modifiers.SEALED |
+                       Modifiers.OVERRIDE |
+                       Modifiers.ABSTRACT |
+                       Modifiers.UNSAFE |
+                       Modifiers.EXTERN |
+                       Modifiers.VIRTUAL;
+
+               public Property (Expression type, string name, int mod_flags,
+                                Accessor get_block, Accessor set_block,
+                                Attributes attrs, Location loc)
+                       : base (type, name, mod_flags, AllowedModifiers,
+                               Parameters.EmptyReadOnlyParameters,
+                               get_block, set_block, attrs, loc)
+               {
+               }
+
                public override bool Define (TypeContainer parent)
                {
                        if (!DoDefine (parent))
                                return false;
 
+                       if (!CheckBase (parent))
+                               return false;
+
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
                        if (Get != null) {
                                Type [] parameters = TypeManager.NoTypes;
 
                                InternalParameters ip = new InternalParameters (
-                                       parent, Parameters.GetEmptyReadOnlyParameters ());
+                                       parent, Parameters.EmptyReadOnlyParameters);
 
                                GetData = new MethodData (this, "get", MemberType,
                                                          parameters, ip, CallingConventions.Standard,
@@ -3126,30 +3725,8 @@ namespace Mono.CSharp {
                        }
                        return true;
                }
-               
-               public void Emit (TypeContainer tc)
-               {
-                       EmitContext ec;
-
-                       ec = new EmitContext (tc, Location, null, MemberType, ModFlags);
-
-                       //
-                       // The PropertyBuilder can be null for explicit implementations, in that
-                       // case, we do not actually emit the ".property", so there is nowhere to
-                       // put the attribute
-                       //
-                       if (PropertyBuilder != null)
-                               Attribute.ApplyAttributes (ec, PropertyBuilder, this, OptAttributes, Location);
-
-                       if (GetData != null)
-                               GetData.Emit (tc, Get.Block, Get);
-
-                       if (SetData != null)
-                               SetData.Emit (tc, Set.Block, Set);
-               }
        }
 
-
        /// </summary>
        ///  Gigantic workaround  for lameness in SRE follows :
        ///  This class derives from EventInfo and attempts to basically
@@ -3335,6 +3912,9 @@ namespace Mono.CSharp {
                        InternalParameters ip = new InternalParameters (
                                parent, new Parameters (parms, null, Location)); 
 
+                       if (!CheckBase (parent))
+                               return false;
+
                        //
                        // Now define the accessors
                        //
@@ -3366,7 +3946,8 @@ namespace Mono.CSharp {
                                        
                                if (Add == null && Remove == null) {
                                        FieldBuilder = parent.TypeBuilder.DefineField (
-                                               Name, MemberType, FieldAttributes.FamANDAssem);
+                                               Name, MemberType,
+                                               FieldAttributes.FamANDAssem | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
                                        TypeManager.RegisterPrivateFieldOfEvent (
                                                (EventInfo) EventBuilder, FieldBuilder);
                                        TypeManager.RegisterFieldBase (FieldBuilder, this);
@@ -3451,7 +4032,7 @@ namespace Mono.CSharp {
        // 
        // int this [ args ]
  
-       public class Indexer : MemberBase {
+       public class Indexer : PropertyBase {
 
                const int AllowedModifiers =
                        Modifiers.NEW |
@@ -3466,13 +4047,6 @@ namespace Mono.CSharp {
                        Modifiers.EXTERN |
                        Modifiers.ABSTRACT;
 
-               public readonly Parameters FormalParameters;
-               public readonly Accessor   Get, Set;
-               public MethodData          GetData;
-               public MethodData          SetData;
-               public MethodBuilder       GetBuilder;
-               public MethodBuilder       SetBuilder;
-               public PropertyBuilder PropertyBuilder;
                public string IndexerName;
                public string InterfaceIndexerName;
 
@@ -3481,18 +4055,14 @@ namespace Mono.CSharp {
                //
                bool IsImplementing = false;
                
-               EmitContext ec;
-               
-               public Indexer (Expression type, string int_type, int flags, Parameters parms,
+               public Indexer (Expression type, string int_type, int flags, Parameters parameters,
                                Accessor get_block, Accessor set_block, Attributes attrs, Location loc)
-                       : base (type, flags, AllowedModifiers, "", attrs, loc)
+                       : base (type, "", flags, AllowedModifiers, parameters, get_block, set_block,
+                               attrs, loc)
                {
                        ExplicitInterfaceName = int_type;
-                       FormalParameters = parms;
-                       Get = get_block;
-                       Set = set_block;
                }
-                       
+
                public override bool Define (TypeContainer parent)
                {
                        PropertyAttributes prop_attr =
@@ -3502,14 +4072,6 @@ namespace Mono.CSharp {
                        if (!DoDefine (parent))
                                return false;
 
-                       Type [] parameters = FormalParameters.GetParameterInfo (parent);
-
-                       // Check if the and arguments were correct
-                       if ((parameters == null) || !CheckParameters (parent, parameters))
-                               return false;
-
-                       ec = new EmitContext (parent, Location, null, MemberType, ModFlags);
-
                        IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
                        if (IndexerName == null)
                                IndexerName = "Item";
@@ -3527,11 +4089,14 @@ namespace Mono.CSharp {
                                Name = ShortName;
                        }
 
+                       if (!CheckBase (parent))
+                               return false;
+
                        if (Get != null){
-                                InternalParameters ip = new InternalParameters (parent, FormalParameters);
+                                InternalParameters ip = new InternalParameters (parent, Parameters);
 
                                GetData = new MethodData (this, "get", MemberType,
-                                                         parameters, ip, CallingConventions.Standard,
+                                                         ParameterTypes, ip, CallingConventions.Standard,
                                                          Get.OptAttributes, ModFlags, flags, false);
 
                                if (!GetData.Define (parent))
@@ -3541,12 +4106,12 @@ namespace Mono.CSharp {
                        }
                        
                        if (Set != null){
-                               int top = parameters.Length;
+                               int top = ParameterTypes.Length;
                                Type [] set_pars = new Type [top + 1];
-                               parameters.CopyTo (set_pars, 0);
+                               ParameterTypes.CopyTo (set_pars, 0);
                                set_pars [top] = MemberType;
 
-                               Parameter [] fixed_parms = FormalParameters.FixedParameters;
+                               Parameter [] fixed_parms = Parameters.FixedParameters;
 
                                if (fixed_parms == null){
                                        throw new Exception ("We currently do not support only array arguments in an indexer");
@@ -3588,7 +4153,7 @@ namespace Mono.CSharp {
                        //
                        // Now name the parameters
                        //
-                       Parameter [] p = FormalParameters.FixedParameters;
+                       Parameter [] p = Parameters.FixedParameters;
                        if (p != null) {
                                int i;
                                
@@ -3606,8 +4171,8 @@ namespace Mono.CSharp {
                                        SetBuilder.DefineParameter (
                                                i + 1, ParameterAttributes.None, "value");
                                        
-                               if (i != parameters.Length) {
-                                       Parameter array_param = FormalParameters.ArrayParameter;
+                               if (i != ParameterTypes.Length) {
+                                       Parameter array_param = Parameters.ArrayParameter;
                                        SetBuilder.DefineParameter (
                                                i + 1, array_param.Attributes, array_param.Name);
                                }
@@ -3624,10 +4189,9 @@ namespace Mono.CSharp {
                        // b) the indexer has a different IndexerName and this is no
                        //    explicit interface implementation.
                        //
-                       if (!IsImplementing ||
-                           (!IsExplicitImpl && (IndexerName != InterfaceIndexerName))){
+                       if (!IsExplicitImpl) {
                                PropertyBuilder = parent.TypeBuilder.DefineProperty (
-                                       IndexerName, prop_attr, MemberType, parameters);
+                                       IndexerName, prop_attr, MemberType, ParameterTypes);
 
                                if (GetData != null)
                                        PropertyBuilder.SetGetMethod (GetBuilder);
@@ -3635,29 +4199,12 @@ namespace Mono.CSharp {
                                if (SetData != null)
                                        PropertyBuilder.SetSetMethod (SetBuilder);
                                
-                               TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder);
+                               TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder,
+                                                            ParameterTypes);
                        }
 
                        return true;
                }
-
-               public void Emit (TypeContainer tc)
-               {
-                       //
-                       // The PropertyBuilder can be null for explicit implementations, in that
-                       // case, we do not actually emit the ".property", so there is nowhere to
-                       // put the attribute
-                       //
-                       if (PropertyBuilder != null)
-                               Attribute.ApplyAttributes (
-                                       ec, PropertyBuilder, this, OptAttributes, Location);
-
-                       if (GetData != null)
-                               GetData.Emit (tc, Get.Block, Get);
-
-                       if (SetData != null)
-                               SetData.Emit (tc, Set.Block, Set);
-               }
        }
 
        public class Operator : MemberCore {
@@ -3772,7 +4319,8 @@ namespace Mono.CSharp {
                        OperatorMethod = new Method (ReturnType, ModFlags, MethodName,
                                                     new Parameters (param_list, null, Location),
                                                     OptAttributes, Mono.CSharp.Location.Null);
-                       
+
+                       OperatorMethod.IsOperator = true;                       
                        OperatorMethod.Define (parent);
 
                        if (OperatorMethod.MethodBuilder == null)
@@ -3782,7 +4330,7 @@ namespace Mono.CSharp {
 
                        Type [] param_types = OperatorMethod.ParameterTypes;
                        Type declaring_type = OperatorMethodBuilder.DeclaringType;
-                       Type return_type = OperatorMethod.GetReturnType (parent);
+                       Type return_type = OperatorMethod.GetReturnType ();
                        Type first_arg_type = param_types [0];
 
                        // Rules for conversion operators
@@ -3892,6 +4440,84 @@ namespace Mono.CSharp {
                        OperatorMethod.Block = Block;
                        OperatorMethod.Emit (parent);
                }
+
+               public static string GetName (OpType ot)
+               {
+                       switch (ot){
+                       case OpType.LogicalNot:
+                               return "!";
+                       case OpType.OnesComplement:
+                               return "~";
+                       case OpType.Increment:
+                               return "++";
+                       case OpType.Decrement:
+                               return "--";
+                       case OpType.True:
+                               return "true";
+                       case OpType.False:
+                               return "false";
+                       case OpType.Addition:
+                               return "+";
+                       case OpType.Subtraction:
+                               return "-";
+                       case OpType.UnaryPlus:
+                               return "+";
+                       case OpType.UnaryNegation:
+                               return "-";
+                       case OpType.Multiply:
+                               return "*";
+                       case OpType.Division:
+                               return "/";
+                       case OpType.Modulus:
+                               return "%";
+                       case OpType.BitwiseAnd:
+                               return "&";
+                       case OpType.BitwiseOr:
+                               return "|";
+                       case OpType.ExclusiveOr:
+                               return "^";
+                       case OpType.LeftShift:
+                               return "<<";
+                       case OpType.RightShift:
+                               return ">>";
+                       case OpType.Equality:
+                               return "==";
+                       case OpType.Inequality:
+                               return "!=";
+                       case OpType.GreaterThan:
+                               return ">";
+                       case OpType.LessThan:
+                               return "<";
+                       case OpType.GreaterThanOrEqual:
+                               return ">=";
+                       case OpType.LessThanOrEqual:
+                               return "<=";
+                       case OpType.Implicit:
+                               return "implicit";
+                       case OpType.Explicit:
+                               return "explicit";
+                       default: return "";
+                       }
+               }
+               
+               public override string ToString ()
+               {
+                       Type return_type = OperatorMethod.GetReturnType();
+                       Type [] param_types = OperatorMethod.ParameterTypes;
+                       
+                       if (SecondArgType == null)
+                               return String.Format (
+                                       "{0} operator {1}({2})",
+                                       TypeManager.CSharpName (return_type),
+                                       GetName (OperatorType),
+                                       param_types [0]);
+                       else
+                               return String.Format (
+                                       "{0} operator {1}({2}, {3})",
+                                       TypeManager.CSharpName (return_type),
+                                       GetName (OperatorType),
+                                       param_types [0], param_types [1]);
+               }
        }
 
        //
@@ -3915,12 +4541,22 @@ namespace Mono.CSharp {
                ///   from the current assembly and class
                /// </summary>
                public static MemberFilter inheritable_method_signature_filter;
+
+               /// <summary>
+               ///   This delegate is used to extract inheritable methods which
+               ///   have the same signature as the argument.  By inheritable,
+               ///   this means that we have permissions to override the method
+               ///   from the current assembly and class
+               /// </summary>
+               public static MemberFilter inheritable_property_signature_filter;
                
                static MethodSignature ()
                {
                        method_signature_filter = new MemberFilter (MemberSignatureCompare);
                        inheritable_method_signature_filter = new MemberFilter (
                                InheritableMemberSignatureCompare);
+                       inheritable_property_signature_filter = new MemberFilter (
+                               InheritablePropertySignatureCompare);
                }
                
                public MethodSignature (string name, Type ret_type, Type [] parameters)
@@ -3971,27 +4607,35 @@ namespace Mono.CSharp {
 
                static bool MemberSignatureCompare (MemberInfo m, object filter_criteria)
                {
-                       MethodInfo mi;
+                       MethodSignature sig = (MethodSignature) filter_criteria;
 
-                       if (! (m is MethodInfo))
+                       if (m.Name != sig.Name)
                                return false;
 
-                       MethodSignature sig = (MethodSignature) filter_criteria;
+                       Type ReturnType;
+                       MethodInfo mi = m as MethodInfo;
+                       PropertyInfo pi = m as PropertyInfo;
 
-                       if (m.Name != sig.Name)
+                       if (mi != null)
+                               ReturnType = mi.ReturnType;
+                       else if (pi != null)
+                               ReturnType = pi.PropertyType;
+                       else
                                return false;
                        
-                       mi = (MethodInfo) m;
-
                        //
                        // we use sig.RetType == null to mean `do not check the
                        // method return value.  
                        //
                        if (sig.RetType != null)
-                               if (mi.ReturnType != sig.RetType)
+                               if (ReturnType != sig.RetType)
                                        return false;
 
-                       Type [] args = TypeManager.GetArgumentTypes (mi);
+                       Type [] args;
+                       if (mi != null)
+                               args = TypeManager.GetArgumentTypes (mi);
+                       else
+                               args = TypeManager.GetArgumentTypes (pi);
                        Type [] sigp = sig.Parameters;
 
                        if (args.Length != sigp.Length)
@@ -4039,5 +4683,46 @@ namespace Mono.CSharp {
                        }
                        return false;
                }
-       }               
+
+               //
+               // This filter should be used when we are requesting properties that
+               // we want to override.
+               //
+               // This makes a number of assumptions, for example
+               // that the methods being extracted are of a parent
+               // class (this means we know implicitly that we are
+               // being called to find out about members by a derived
+               // class).
+               // 
+               static bool InheritablePropertySignatureCompare (MemberInfo m, object filter_criteria)
+               {
+                       if (MemberSignatureCompare (m, filter_criteria)){
+                               PropertyInfo pi = (PropertyInfo) m;
+
+                               MethodInfo inherited_get = TypeManager.GetPropertyGetter (pi);
+                               MethodInfo inherited_set = TypeManager.GetPropertySetter (pi);
+
+                               MethodInfo mi = inherited_get == null ? inherited_set : inherited_get;
+
+                               MethodAttributes prot = mi.Attributes & MethodAttributes.MemberAccessMask;
+
+                               // If only accessible to the current class.
+                               if (prot == MethodAttributes.Private)
+                                       return false;
+
+                               // If only accessible to the defining assembly or 
+                               if (prot == MethodAttributes.FamANDAssem ||
+                                   prot == MethodAttributes.Assembly){
+                                       if (m.DeclaringType.Assembly == CodeGen.AssemblyBuilder)
+                                               return true;
+                                       else
+                                               return false;
+                               }
+
+                               // Anything else (FamOrAssembly and Public) is fine
+                               return true;
+                       }
+                       return false;
+               }
+       }
 }