Committing Miguel's type lookup patch.
[mono.git] / mcs / mcs / class.cs
index dbfa3291e0eee148ac5f5f532fc8139cde2d0416..584826ba5b49a3117db292b1ff6cee00f969bb5a 100755 (executable)
@@ -5,14 +5,14 @@
 //
 // Licensed under the terms of the GNU GPL
 //
-// (C) 2001 Ximian, Inc (http://www.ximian.com)
+// (C) 2001, 2002 Ximian, Inc (http://www.ximian.com)
 //
 //
 
+using System;
 using System.Collections;
 using System.Reflection;
 using System.Reflection.Emit;
-using System;
 using System.Runtime.CompilerServices;
 using System.Diagnostics.SymbolStore;
 
@@ -67,6 +67,9 @@ namespace Mono.CSharp {
                // Holds the operators
                ArrayList operators;
 
+               // The emit context for toplevel objects.
+               EmitContext ec;
+               
                //
                // Pointers to the default constructor and the default static constructor
                //
@@ -77,6 +80,11 @@ namespace Mono.CSharp {
                // Whether we have seen a static constructor for this class or not
                //
                bool have_static_constructor = false;
+
+               //
+               // Whether we have at least one non-static field
+               //
+               bool have_nonstatic_fields = false;
                
                //
                // This one is computed after we can distinguish interfaces
@@ -94,7 +102,14 @@ namespace Mono.CSharp {
                public AttributeTargets Targets = AttributeTargets.All;
                public bool AllowMultiple = false;
                public bool Inherited;
+
+               // The interfaces we implement.
+               Type [] ifaces;
                
+               //
+               // The indexer name for this class
+               //
+               public string IndexerName;
 
                public TypeContainer (TypeContainer parent, string name, Location l)
                        : base (parent, name, l)
@@ -203,7 +218,11 @@ namespace Mono.CSharp {
                        if (methods == null)
                                methods = new ArrayList ();
 
-                       methods.Add (method);
+                       if (method.Name.IndexOf (".") != -1)
+                               methods.Insert (0, method);
+                       else 
+                               methods.Add (method);
+                       
                        if (value != null)
                                DefineName (name, method);
 
@@ -262,13 +281,13 @@ namespace Mono.CSharp {
                {
                        AdditionResult res;
                        string name = field.Name;
-                       
+
                        if ((res = IsValid (name)) != AdditionResult.Success)
                                return res;
-
+                       
                        if (fields == null)
                                fields = new ArrayList ();
-
+                       
                        fields.Add (field);
                        
                        if (field.Initializer != null){
@@ -290,7 +309,10 @@ namespace Mono.CSharp {
                                        initialized_fields.Add (field);
                                }
                        }
-                       
+
+                       if ((field.ModFlags & Modifiers.STATIC) == 0)
+                               have_nonstatic_fields = true;
+
                        DefineName (name, field);
                        return AdditionResult.Success;
                }
@@ -306,7 +328,10 @@ namespace Mono.CSharp {
                        if (properties == null)
                                properties = new ArrayList ();
 
-                       properties.Add (prop);
+                       if (prop.Name.IndexOf (".") != -1)
+                               properties.Insert (0, prop);
+                       else
+                               properties.Add (prop);
                        DefineName (name, prop);
 
                        return AdditionResult.Success;
@@ -334,7 +359,10 @@ namespace Mono.CSharp {
                        if (indexers == null)
                                indexers = new ArrayList ();
 
-                       indexers.Add (i);
+                       if (i.InterfaceType != null)
+                               indexers.Insert (0, i);
+                       else
+                               indexers.Add (i);
 
                        return AdditionResult.Success;
                }
@@ -401,6 +429,10 @@ namespace Mono.CSharp {
                        get {
                                return fields;
                        }
+
+                       set {
+                               fields = value;
+                       }
                }
 
                public ArrayList InstanceConstructors {
@@ -490,21 +522,23 @@ namespace Mono.CSharp {
                                if (init is Expression)
                                        e = (Expression) init;
                                else {
-                                       string base_type = f.Type.Substring (0, f.Type.IndexOf ("["));
-                                       string rank = f.Type.Substring (f.Type.IndexOf ("["));
-                                       e = new ArrayCreation (base_type, rank, (ArrayList)init, f.Location);
+                                       e = new ArrayCreation (f.Type, "", (ArrayList)init, f.Location);
                                }
 
                                Location l = f.Location;
                                FieldExpr fe = new FieldExpr (f.FieldBuilder, l);
                                fe.InstanceExpression = instance_expr;
-                               Assign a = new Assign (fe, e, l);
-                               
-                               a = (Assign) a.Resolve (ec);
+                               Expression a = new Assign (fe, e, l);
+
+                               a = a.Resolve (ec);
                                if (a == null)
                                        return false;
 
-                               a.EmitStatement (ec);
+                               if (a is ExpressionStatement)
+                                       ((ExpressionStatement) a).EmitStatement (ec);
+                               else {
+                                       throw new Exception ("Assign.Resolve returned a non ExpressionStatement");
+                               }
                        }
                        
                        return true;
@@ -545,186 +579,10 @@ namespace Mono.CSharp {
                        }
                }
 
-               struct TypeAndMethods {
-                       public Type          type;
-                       public MethodInfo [] methods;
-
-                       // Far from ideal, but we want to avoid creating a copy
-                       // of methods above.
-                       public Type [][]     args;
-
-                       //
-                       // This flag on the method says `We found a match, but
-                       // because it was private, we could not use the match
-                       //
-                       public bool []       found;
-               }
-
-               //
-               // This array keeps track of the pending implementations
-               // 
-               TypeAndMethods [] pending_implementations;
-
-               //
-               // Returns a list of the abstract methods that are exposed by all of our
-               // parents that we must implement.  Notice that this `flattens' the
-               // method search space, and takes into account overrides.  
-               //
-               ArrayList GetAbstractMethods (Type t)
-               {
-                       ArrayList list = null;
-                       bool searching = true;
-                       Type current_type = t;
-                       
-                       do {
-                               MemberInfo [] mi;
-                               
-                               mi = FindMembers (
-                                       current_type, MemberTypes.Method,
-                                       BindingFlags.Public | BindingFlags.Instance |
-                                       BindingFlags.DeclaredOnly,
-                                       virtual_method_filter, null);
-
-                               if (current_type == TypeManager.object_type)
-                                       searching = false;
-                               else {
-                                       current_type = current_type.BaseType;
-                                       if (!current_type.IsAbstract)
-                                               searching = false;
-                               }
-
-                               if (mi == null)
-                                       continue;
-
-                               int count = mi.Length;
-                               if (count == 0)
-                                       continue;
-
-                               if (count == 1 && !(mi [0] is MethodBase))
-                                       searching = false;
-                               else 
-                                       list = TypeManager.CopyNewMethods (list, mi);
-                       } while (searching);
-
-                       if (list == null)
-                               return null;
-                       
-                       for (int i = 0; i < list.Count; i++){
-                               while (list.Count > i && !((MethodInfo) list [i]).IsAbstract)
-                                       list.RemoveAt (i);
-                       }
-
-                       if (list.Count == 0)
-                               return null;
-
-                       return list;
-               }
-               
-               //
-               // Registers the required method implementations for this class
-               //
-               // Register method implementations are either abstract methods
-               // flagged as such on the base class or interface methods
-               //
-               public void RegisterRequiredImplementations ()
-               {
-                       Type [] ifaces = TypeBuilder.GetInterfaces ();
-                       Type b = TypeBuilder.BaseType;
-                       int icount = 0;
-
-#if DEBUG
-                       {
-                               Type x = TypeBuilder;
-
-                               while (x != null){
-                                       Type [] iff = x.GetInterfaces ();
-                                       Console.WriteLine ("Type: " + x.Name);
-                                       
-                                       foreach (Type tt in iff){
-                                               Console.WriteLine ("  Iface: " + tt.Name);
-                                       }
-                                       x = x.BaseType;
-                               }
-                       }
-#endif
-                                       
-                       icount = ifaces.Length;
-
-                       //
-                       // If we are implementing an abstract class, and we are not
-                       // ourselves abstract, and there are abstract methods (C# allows
-                       // abstract classes that have no abstract methods), then allocate
-                       // one slot.
-                       //
-                       // We also pre-compute the methods.
-                       //
-                       bool implementing_abstract = (b.IsAbstract && !TypeBuilder.IsAbstract);
-                       ArrayList abstract_methods = null;
-
-                       if (implementing_abstract){
-                               abstract_methods = GetAbstractMethods (b);
-                               
-                               if (abstract_methods == null)
-                                       implementing_abstract = false;
-                       }
-                       
-                       int total = icount +  (implementing_abstract ? 1 : 0);
-                       if (total == 0)
-                               return;
-
-                       pending_implementations = new TypeAndMethods [total];
-                       
-                       int i = 0;
-                       if (ifaces != null){
-                               foreach (Type t in ifaces){
-                                       MethodInfo [] mi;
-
-                                       if (t is TypeBuilder){
-                                               Interface iface;
-
-                                               iface = TypeManager.LookupInterface (t);
-                                               
-                                               mi = iface.GetMethods ();
-                                       } else
-                                               mi = t.GetMethods ();
-
-                                       int count = mi.Length;
-                                       pending_implementations [i].type = t;
-                                       pending_implementations [i].methods = mi;
-                                       pending_implementations [i].args = new Type [count][];
-                                       pending_implementations [i].found = new bool [count];
-
-                                       int j = 0;
-                                       foreach (MethodInfo m in mi){
-                                               Type [] types = TypeManager.GetArgumentTypes (m);
-
-                                               pending_implementations [i].args [j] = types;
-                                               j++;
-                                       }
-                                       i++;
-                               }
-                       }
-
-                       if (abstract_methods != null){
-                               int count = abstract_methods.Count;
-                               pending_implementations [i].methods = new MethodInfo [count];
-                               
-                               abstract_methods.CopyTo (pending_implementations [i].methods, 0);
-                               pending_implementations [i].found = new bool [count];
-                               pending_implementations [i].args = new Type [count][];
-                               pending_implementations [i].type = TypeBuilder;
-                               
-                               int j = 0;
-                               foreach (MemberInfo m in abstract_methods){
-                                       MethodInfo mi = (MethodInfo) m;
-                                       
-                                       Type [] types = TypeManager.GetArgumentTypes (mi);
-                                       
-                                       pending_implementations [i].args [j] = types;
-                                       j++;
-                               }
-                       }
-               }
+               /// <remarks>
+               ///  The pending methods that need to be implemented (interfaces or abstract methods)
+               /// </remarks>
+               public PendingImplementation Pending;
 
                /// <summary>
                ///   This function computes the Base class and also the
@@ -774,14 +632,16 @@ namespace Mono.CSharp {
                        count = bases.Count;
 
                        if (is_class){
-                               string name = (string) bases [0];
-                               Type first = FindType (name);
+                               Expression name = (Expression) bases [0];
+                               name = ResolveTypeExpr (name, false, Location);
 
-                               if (first == null){
+                               if (name == null){
                                        error = true;
                                        return null;
                                }
 
+                               Type first = name.Type;
+
                                if (first.IsClass){
                                        parent = first;
                                        start = 1;
@@ -797,9 +657,11 @@ namespace Mono.CSharp {
                        Type [] ifaces = new Type [count-start];
                        
                        for (i = start, j = 0; i < count; i++, j++){
-                               string name = (string) bases [i];
-                               Type t = FindType (name);
-                               
+                               Expression name = (Expression) bases [i];
+                               Expression resolved = ResolveTypeExpr (name, false, Location);
+                               bases [i] = resolved;
+                               Type t = resolved.Type;
+
                                if (t == null){
                                        error = true;
                                        return null;
@@ -833,11 +695,19 @@ namespace Mono.CSharp {
                                                return null;
                                        }
                                }
+
+                               for (int x = 0; x < j; x++) {
+                                       if (t == ifaces [x]) {
+                                               Report.Error (528, "`" + name + "' is already listed in interface list");
+                                               error = true;
+                                               return null;
+                                       }
+                               }
                                
                                ifaces [j] = t;
                        }
 
-                       return ifaces;
+                       return TypeManager.ExpandInterfaces (ifaces);
                }
                
                //
@@ -846,7 +716,6 @@ namespace Mono.CSharp {
                public override TypeBuilder DefineType ()
                {
                        Type parent;
-                       Type [] ifaces;
                        bool error;
                        bool is_class;
 
@@ -863,6 +732,8 @@ namespace Mono.CSharp {
                        else
                                is_class = false;
 
+                       ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
+
                        ifaces = GetClassBases (is_class, out parent, out error); 
                        
                        if (error)
@@ -883,6 +754,8 @@ namespace Mono.CSharp {
                        if (!is_class && TypeManager.value_type == null)
                                throw new Exception ();
 
+                       TypeAttributes type_attributes = TypeAttr;
+
                        // if (parent_builder is ModuleBuilder) {
                        if (IsTopLevel){
                                ModuleBuilder builder = CodeGen.ModuleBuilder;
@@ -892,9 +765,9 @@ namespace Mono.CSharp {
                                // appended
                                //
 
-                               if (!is_class && Fields == null)
+                               if (!is_class && !have_nonstatic_fields)
                                        TypeBuilder = builder.DefineType (Name,
-                                                                         TypeAttr,
+                                                                         type_attributes,
                                                                          parent, 
                                                                          PackingSize.Unspecified, 1);
                                else
@@ -902,7 +775,7 @@ namespace Mono.CSharp {
                                // classes or structs with fields
                                //
                                        TypeBuilder = builder.DefineType (Name,
-                                                                         TypeAttr,
+                                                                         type_attributes,
                                                                          parent,
                                                                          ifaces);
                        } else {
@@ -912,9 +785,9 @@ namespace Mono.CSharp {
                                // Structs with no fields need to have a ".size 1"
                                // appended
                                //
-                               if (!is_class && Fields == null)
+                               if (!is_class && !have_nonstatic_fields)
                                        TypeBuilder = builder.DefineNestedType (Basename,
-                                                                               TypeAttr,
+                                                                               type_attributes,
                                                                                parent, 
                                                                                PackingSize.Unspecified);
                                else {
@@ -922,16 +795,28 @@ namespace Mono.CSharp {
                                        // classes or structs with fields
                                        //
                                        TypeBuilder = builder.DefineNestedType (Basename,
-                                                                               TypeAttr,
+                                                                               type_attributes,
                                                                                parent,
                                                                                ifaces);
                                }
                        }
 
-                       TypeManager.AddUserType (Name, TypeBuilder, this);
+                       // add interfaces that were not added at type creation (weird API issue)
+                       if (!is_class && !have_nonstatic_fields && (ifaces != null)) {
+                               foreach (Type i in ifaces)
+                                       TypeBuilder.AddInterfaceImplementation (i);
+                       }
+                       
+                       //
+                       // Finish the setup for the EmitContext
+                       //
+                       ec.ContainerType = TypeBuilder;
+
+                       TypeManager.AddUserType (Name, TypeBuilder, this, ifaces);
 
-                       if (parent == TypeManager.attribute_type ||
-                           parent.IsSubclassOf (TypeManager.attribute_type)) {
+                       if ((parent != null) &&
+                           (parent == TypeManager.attribute_type ||
+                            parent.IsSubclassOf (TypeManager.attribute_type))) {
                                RootContext.RegisterAttribute (this);
                                TypeManager.RegisterAttrType (TypeBuilder, this);
                        } else
@@ -983,38 +868,29 @@ namespace Mono.CSharp {
                                                
                                if (defined_names == null)
                                        continue;
-                               
+
                                idx = Array.BinarySearch (defined_names, mc.Name, mif_compare);
-                               
                                if (idx < 0){
                                        if (RootContext.WarningLevel >= 4){
                                                if ((mc.ModFlags & Modifiers.NEW) != 0)
-                                                       Report109 (mc.Location, mc);
+                                                       Warning_KewywordNewNotRequired (mc.Location, mc);
                                        }
                                        continue;
                                }
 
-                               if (defined_names [idx] is PropertyInfo &&
-                                   ((mc.ModFlags & Modifiers.OVERRIDE) != 0)){
+                               MemberInfo match = defined_names [idx];
+
+                               if (match is PropertyInfo && ((mc.ModFlags & Modifiers.OVERRIDE) != 0))
                                        continue;
-                               }
-                                   
-#if WANT_TO_VERIFY_SIGNATURES_HERE
-                               if (defined_names [idx] is MethodBase && mc is MethodCore){
-                                       MethodBase mb = (MethodBase) defined_names [idx];
-                                       MethodCore met = (MethodCore) mc;
-                                       
-                                       if ((mb.IsVirtual || mb.IsAbstract) &&
-                                           (mc.ModFlags & Modifiers.OVERRIDE) != 0)
-                                               continue;
 
-                                       //
-                                       // FIXME: Compare the signatures here.  If they differ,
-                                       // then: `continue;' 
-                               }
-#endif
+                               //
+                               // If we are both methods, let the method resolution emit warnings
+                               //
+                               if (match is MethodBase && mc is MethodCore)
+                                       continue; 
+                               
                                if ((mc.ModFlags & Modifiers.NEW) == 0)
-                                       Report108 (mc.Location, defined_names [idx]);
+                                       Warning_KeywordNewRequired (mc.Location, defined_names [idx]);
                        }
                        
                        foreach (object o in remove_list)
@@ -1022,6 +898,42 @@ namespace Mono.CSharp {
                        
                        remove_list.Clear ();
                }
+
+               //
+               // Defines the indexers, and also verifies that the IndexerNameAttribute in the
+               // class is consisten.  Either it is `Item' or it is the name defined by all the
+               // indexers with the `IndexerName' attribute.
+               //
+               // Turns out that the IndexerNameAttribute is applied to each indexer,
+               // but it is never emitted, instead a DefaultName attribute is attached
+               // to the class.
+               //
+               void DefineIndexers ()
+               {
+                       string class_indexer_name = null;
+                       
+                       foreach (Indexer i in Indexers){
+                               string name;
+                               
+                               i.Define (this);
+
+                               name = i.IndexerName;
+                               if (class_indexer_name == null){
+                                       class_indexer_name = name;
+                                       continue;
+                               }
+                               
+                               if (name == class_indexer_name)
+                                       continue;
+                               
+                               Report.Error (
+                                       668, "Two indexers have different names, " +
+                                       " you should use the same name for all your indexers");
+                       }
+                       if (class_indexer_name == null)
+                               class_indexer_name = "Item";
+                       IndexerName = class_indexer_name;
+               }
                
                /// <summary>
                ///   Populates our TypeBuilder with fields and methods
@@ -1078,8 +990,8 @@ namespace Mono.CSharp {
                                        ReportStructInitializedInstanceError ();
                        }
 
-                       RegisterRequiredImplementations ();
-
+                       Pending = PendingImplementation.GetPendingImplementations (this);
+                       
                        //
                        // Constructors are not in the defined_names array
                        //
@@ -1090,7 +1002,7 @@ namespace Mono.CSharp {
                                default_static_constructor.Define (this);
                        
                        if (methods != null)
-                               DefineMembers (methods, null);
+                               DefineMembers (methods, defined_names);
 
                        if (properties != null)
                                DefineMembers (properties, defined_names);
@@ -1099,9 +1011,9 @@ namespace Mono.CSharp {
                                DefineMembers (events, defined_names);
 
                        if (indexers != null) {
-                               foreach (Indexer i in Indexers)
-                                       i.Define (this);
-                       }
+                               DefineIndexers ();
+                       } else
+                               IndexerName = "Item";
 
                        if (operators != null)
                                DefineMembers (operators, null);
@@ -1115,17 +1027,6 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               /// <summary>
-               ///   Looks up the alias for the name
-               /// </summary>
-               public string LookupAlias (string name)
-               {
-                       if (Namespace != null)
-                               return Namespace.LookupAlias (name);
-                       else
-                               return null;
-               }
-               
                /// <summary>
                ///   This function is based by a delegate to the FindMembers routine
                /// </summary>
@@ -1140,19 +1041,6 @@ namespace Mono.CSharp {
                /// </summary>
                static MemberFilter accepting_filter;
 
-               static bool IsVirtualFilter (MemberInfo m, object filterCriteria)
-               {
-                       if (!(m is MethodInfo))
-                               return false;
-
-                       return ((MethodInfo) m).IsVirtual;
-               }
-               
-               /// <summary>
-               ///   This filter is used by FindMembers, and it is used to
-               ///   extract only virtual/abstract fields
-               /// </summary>
-               static MemberFilter virtual_method_filter;
                
                /// <summary>
                ///   A member comparission method based on name only
@@ -1162,7 +1050,6 @@ namespace Mono.CSharp {
                static TypeContainer ()
                {
                        accepting_filter = new MemberFilter (AlwaysAccept);
-                       virtual_method_filter = new MemberFilter (IsVirtualFilter);
                        mif_compare = new MemberInfoCompare ();
                }
                
@@ -1191,10 +1078,9 @@ namespace Mono.CSharp {
                        ArrayList members = new ArrayList ();
                        bool priv = (bf & BindingFlags.NonPublic) != 0;
 
-                       priv = true;
                        if (filter == null)
                                filter = accepting_filter; 
-                       
+
                        if ((mt & MemberTypes.Field) != 0) {
                                if (fields != null) {
                                        foreach (Field f in fields) {
@@ -1306,17 +1192,32 @@ namespace Mono.CSharp {
                        }
                        
                        if ((mt & MemberTypes.NestedType) != 0) {
+                               if (types != null){
+                                       foreach (TypeContainer t in types) {
+                                               TypeBuilder tb = t.TypeBuilder;
 
-                               if (Types != null)
-                                       foreach (TypeContainer t in Types)  
-                                               if (filter (t.TypeBuilder, criteria) == true)
-                                                       members.Add (t.TypeBuilder);
+                                               if (tb != null && (filter (tb, criteria) == true))
+                                                               members.Add (tb);
+                                       }
+                               }
 
-                               if (Enums != null)
-                                       foreach (Enum en in Enums)
-                                               if (filter (en.TypeBuilder, criteria) == true)
-                                                       members.Add (en.TypeBuilder);
+                               if (enums != null){
+                                       foreach (Enum en in enums){
+                                               TypeBuilder tb = en.TypeBuilder;
+
+                                               if (tb != null && (filter (tb, criteria) == true))
+                                                       members.Add (tb);
+                                       }
+                               }
                                
+                               if (delegates != null){
+                                       foreach (Delegate d in delegates){
+                                               TypeBuilder tb = d.TypeBuilder;
+                                               
+                                               if (tb != null && (filter (tb, criteria) == true))
+                                                       members.Add (tb);
+                                       }
+                               }
                        }
 
                        if ((mt & MemberTypes.Constructor) != 0){
@@ -1334,6 +1235,7 @@ namespace Mono.CSharp {
                                        ConstructorBuilder cb =
                                                default_static_constructor.ConstructorBuilder;
                                        
+                                       if (cb != null)
                                        if (filter (cb, criteria) == true)
                                                members.Add (cb);
                                }
@@ -1342,7 +1244,7 @@ namespace Mono.CSharp {
                        //
                        // Lookup members in parent if requested.
                        //
-                       if ((bf & BindingFlags.DeclaredOnly) == 0){
+                       if (((bf & BindingFlags.DeclaredOnly) == 0) && (TypeBuilder.BaseType != null)) {
                                MemberInfo [] mi;
 
                                mi = FindMembers (TypeBuilder.BaseType, mt, bf, filter, criteria);
@@ -1360,21 +1262,7 @@ namespace Mono.CSharp {
                        return null;
                }
 
-               public MemberInfo GetFieldFromEvent (EventExpr event_expr)
-               {
-                       EventInfo ei = event_expr.EventInfo;
-
-                       foreach (Event e in events) { 
-
-                               if (e.FieldBuilder == null)
-                                       continue;
-                               
-                               if (Type.FilterName (e.FieldBuilder, ei.Name))
-                                       return e.FieldBuilder;
-                       }
-
-                       return null;
-               }
+               
 
                public static MemberInfo [] FindMembers (Type t, MemberTypes mt, BindingFlags bf,
                                                         MemberFilter filter, object criteria)
@@ -1397,202 +1285,6 @@ namespace Mono.CSharp {
                        return null;
                }
 
-               /// <summary>
-               ///   Whether the specified method is an interface method implementation
-               /// </summary>
-               ///
-               /// <remarks>
-               ///   If a method in Type `t' (or null to look in all interfaces
-               ///   and the base abstract class) with name `Name', return type `ret_type' and
-               ///   arguments `args' implements an interface, this method will
-               ///   return the MethodInfo that this method implements.
-               ///
-               ///   This will remove the method from the list of "pending" methods
-               ///   that are required to be implemented for this class as a side effect.
-               /// 
-               /// </remarks>
-               public MethodInfo IsInterfaceMethod (Type t, string Name, Type ret_type, Type [] args,
-                                                    bool clear)
-               {
-                       int arg_len = args.Length;
-
-                       if (pending_implementations == null)
-                               return null;
-
-                       foreach (TypeAndMethods tm in pending_implementations){
-                               if (!(t == null || tm.type == t))
-                                       continue;
-
-                               int i = 0;
-                               foreach (MethodInfo m in tm.methods){
-                                       if (m == null){
-                                               i++;
-                                               continue;
-                                       }
-
-                                       if (Name != m.Name){
-                                               i++;
-                                               continue;
-                                       }
-
-                                       if (ret_type != m.ReturnType){
-                                               if (!((ret_type == null && m.ReturnType == TypeManager.void_type) ||
-                                                     (m.ReturnType == null && ret_type == TypeManager.void_type)))
-                                               {
-                                                       i++;
-                                                       continue;
-                                               }
-                                       }
-
-                                       //
-                                       // Check if we have the same parameters
-                                       //
-                                       if (tm.args [i].Length != arg_len){
-                                               i++;
-                                               continue;
-                                       }
-
-                                       int j, top = args.Length;
-                                       bool fail = false;
-                                       
-                                       for (j = 0; j < top; j++){
-                                               if (tm.args [i][j] != args[j]){
-                                                       fail = true;
-                                                       break;
-                                               }
-                                       }
-                                       if (fail){
-                                               i++;
-                                               continue;
-                                       }
-
-                                       if (clear)
-                                               tm.methods [i] = null;
-                                       tm.found [i] = true;
-                                       return m;
-                               }
-
-                               // If a specific type was requested, we can stop now.
-                               if (tm.type == t)
-                                       return null;
-                       }
-                       return null;
-               }
-
-               /// <summary>
-               ///   C# allows this kind of scenarios:
-               ///   interface I { void M (); }
-               ///   class X { public void M (); }
-               ///   class Y : X, I { }
-               ///
-               ///   For that case, we create an explicit implementation function
-               ///   I.M in Y.
-               /// </summary>
-               void DefineProxy (Type iface, MethodInfo parent_method, MethodInfo iface_method,
-                                 Type [] args)
-               {
-                       MethodBuilder proxy;
-
-                       string proxy_name = iface.Name + "." + iface_method.Name;
-
-                       proxy = TypeBuilder.DefineMethod (
-                               proxy_name,
-                               MethodAttributes.HideBySig |
-                               MethodAttributes.NewSlot |
-                               MethodAttributes.Virtual,
-                               CallingConventions.Standard | CallingConventions.HasThis,
-                               parent_method.ReturnType, args);
-
-                       int top = args.Length;
-                       ILGenerator ig = proxy.GetILGenerator ();
-
-                       ig.Emit (OpCodes.Ldarg_0);
-                       for (int i = 0; i < top; i++){
-                               switch (i){
-                               case 0:
-                                       ig.Emit (OpCodes.Ldarg_1); break;
-                               case 1:
-                                       ig.Emit (OpCodes.Ldarg_2); break;
-                               case 2:
-                                       ig.Emit (OpCodes.Ldarg_3); break;
-                               default:
-                                       ig.Emit (OpCodes.Ldarg, i - 1); break;
-                               }
-                       }
-                       ig.Emit (OpCodes.Call, parent_method);
-                       ig.Emit (OpCodes.Ret);
-
-                       TypeBuilder.DefineMethodOverride (proxy, iface_method);
-               }
-               
-               /// <summary>
-               ///   This function tells whether one of our parent classes implements
-               ///   the given method (which turns out, it is valid to have an interface
-               ///   implementation in a parent
-               /// </summary>
-               bool ParentImplements (Type iface_type, MethodInfo mi)
-               {
-                       MethodSignature ms;
-                       
-                       Type [] args = TypeManager.GetArgumentTypes (mi);
-                       ms = new MethodSignature (mi.Name, mi.ReturnType, args);
-                       MemberInfo [] list = FindMembers (
-                               TypeBuilder.BaseType, MemberTypes.Method | MemberTypes.Property,
-                               BindingFlags.Public | BindingFlags.Instance,
-                               MethodSignature.method_signature_filter, ms);
-
-                       if (list == null || list.Length == 0)
-                               return false;
-                       
-                       DefineProxy (iface_type, (MethodInfo) list [0], mi, args);
-                       return true;
-               }
-               
-               /// <summary>
-               ///   Verifies that any pending abstract methods or interface methods
-               ///   were implemented.
-               /// </summary>
-               bool VerifyPendingMethods ()
-               {
-                       int top = pending_implementations.Length;
-                       bool errors = false;
-                       int i;
-                       
-                       for (i = 0; i < top; i++){
-                               Type type = pending_implementations [i].type;
-                               int j = 0;
-                               
-                               foreach (MethodInfo mi in pending_implementations [i].methods){
-                                       if (mi == null)
-                                               continue;
-
-                                       if (type.IsInterface){
-                                               if (ParentImplements (type, mi))
-                                                       continue;
-                                               string extra = "";
-                                               
-                                               if (pending_implementations [i].found [j])
-                                                       extra = ".  (method might be private or static)";
-                                               Report.Error (
-                                                       536, Location,
-                                                       "`" + Name + "' does not implement " +
-                                                       "interface member `" +
-                                                       type.FullName + "." + mi.Name + "'" + extra);
-                                       } else {
-                                               Report.Error (
-                                                       534, Location,
-                                                       "`" + Name + "' does not implement " +
-                                                       "inherited abstract member `" +
-                                                       type.FullName + "." + mi.Name + "'");
-                                       }
-                                       errors = true;
-                                       j++;
-                               }
-                       }
-                       return errors;
-               }
-
                /// <summary>
                ///   Emits the values for the constants
                /// </summary>
@@ -1603,7 +1295,7 @@ namespace Mono.CSharp {
                                        con.EmitConstant (this);
                        return;
                }
-               
+
                /// <summary>
                ///   Emits the code, this step is performed after all
                ///   the types, enumerations, constructors
@@ -1629,12 +1321,12 @@ namespace Mono.CSharp {
                                foreach (Property p in properties)
                                        p.Emit (this);
 
-                       if (indexers != null) {
+                       if (indexers != null){
                                foreach (Indexer ix in indexers)
                                        ix.Emit (this);
-
-                               CustomAttributeBuilder cb = Interface.EmitDefaultMemberAttr (this, ModFlags, Location);
-
+                               
+                               CustomAttributeBuilder cb = Interface.EmitDefaultMemberAttr (
+                                       this, IndexerName, ModFlags, Location);
                                TypeBuilder.SetCustomAttribute (cb);
                        }
                        
@@ -1647,14 +1339,10 @@ namespace Mono.CSharp {
                                        e.Emit (this);
                        }
 
-                       if (pending_implementations != null)
-                               if (!VerifyPendingMethods ())
+                       if (Pending != null)
+                               if (Pending.VerifyPendingMethods ())
                                        return;
                        
-                       EmitContext ec = new EmitContext (
-                                                 this, Mono.CSharp.Location.Null, null, null,
-                                                 ModFlags);
-
                        Attribute.ApplyAttributes (ec, TypeBuilder, this, OptAttributes, Location);
 
                        //
@@ -1740,7 +1428,7 @@ namespace Mono.CSharp {
                        return "`" + Name + "." + n + "'";
                }
 
-               public void Report108 (Location l, MemberInfo mi)
+               public void Warning_KeywordNewRequired (Location l, MemberInfo mi)
                {
                        Report.Warning (
                                108, l, "The keyword new is required on " + 
@@ -1748,7 +1436,7 @@ namespace Mono.CSharp {
                                mi.ReflectedType.Name + "." + mi.Name + "'");
                }
 
-               public void Report109 (Location l, MemberCore mc)
+               public void Warning_KewywordNewNotRequired (Location l, MemberCore mc)
                {
                        Report.Warning (
                                109, l, "The member " + MakeName (mc.Name) + " does not hide an " +
@@ -1767,6 +1455,7 @@ namespace Mono.CSharp {
                public bool MethodModifiersValid (int flags, string n, Location loc)
                {
                        const int vao = (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE);
+                       const int va = (Modifiers.VIRTUAL | Modifiers.ABSTRACT);
                        const int nv = (Modifiers.NEW | Modifiers.VIRTUAL);
                        bool ok = true;
                        string name = MakeName (n);
@@ -1783,6 +1472,13 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (this is Struct){
+                               if ((flags & va) != 0){
+                                       Modifiers.Error_InvalidModifier (loc, "virtual or abstract");
+                                       ok = false;
+                               }
+                       }
+
                        if ((flags & Modifiers.OVERRIDE) != 0 && (flags & nv) != 0){
                                Report.Error (
                                        113, loc, name +
@@ -1854,6 +1550,37 @@ namespace Mono.CSharp {
                                builder_and_args = new Hashtable ();
                        return true;
                }
+
+               /// <summary>
+               ///   Performs checks for an explicit interface implementation.  First it
+               ///   checks whether the `interface_type' is a base inteface implementation.
+               ///   Then it checks whether `name' exists in the interface type.
+               /// </summary>
+               public bool VerifyImplements (Type interface_type, string full, string name, Location loc)
+               {
+                       bool found = false;
+
+                       if (ifaces != null){
+                               foreach (Type t in ifaces){
+                                       if (t == interface_type){
+                                               found = true;
+                                               break;
+                                       }
+                               }
+                       }
+                       
+                       if (!found){
+                               Report.Error (540, "`" + full + "': containing class does not implement interface `" + interface_type.FullName + "'");
+                               return false;
+                       }
+
+                       return true;
+               }
+
+               public static void Error_ExplicitInterfaceNotMemberInterface (Location loc, string name)
+               {
+                       Report.Error (539, loc, "Explicit implementation: `" + name + "' is not a member of the interface");
+               }
        }
 
        public class Class : TypeContainer {
@@ -2062,7 +1789,7 @@ namespace Mono.CSharp {
        }
        
        public class Method : MethodCore {
-               public readonly string ReturnType;
+               public Expression ReturnType;
                public MethodBuilder MethodBuilder;
                public readonly Attributes OptAttributes;
 
@@ -2088,7 +1815,7 @@ namespace Mono.CSharp {
                //
                // return_type can be "null" for VOID values.
                //
-               public Method (string return_type, int mod, string name, Parameters parameters,
+               public Method (Expression return_type, int mod, string name, Parameters parameters,
                               Attributes attrs, Location l)
                        : base (name, parameters, l)
                {
@@ -2107,8 +1834,7 @@ namespace Mono.CSharp {
                public Type GetReturnType (TypeContainer parent)
                {
                        if (type_return_type == null)
-                               type_return_type = RootContext.LookupType (
-                                       parent, ReturnType, false, Location);
+                               type_return_type = parent.ResolveType (ReturnType, false, Location);
                        
                        return type_return_type;
                }
@@ -2163,7 +1889,7 @@ namespace Mono.CSharp {
                        Type ret_type = GetReturnType (parent);
                        Type [] parameters = ParameterTypes (parent);
                        bool error = false;
-                       MethodInfo implementing;
+                       MethodInfo implementing = null;
                        Type iface_type = null;
                        string iface = "", short_name;
                        bool explicit_impl = false;
@@ -2204,7 +1930,7 @@ namespace Mono.CSharp {
 
                        // ptype is only null for System.Object while compiling corlib.
                        if (ptype != null){
-                               MethodSignature ms = new MethodSignature (Name, ret_type, parameters);
+                               MethodSignature ms = new MethodSignature (Name, null, parameters);
                                MemberInfo [] mi, mi_static, mi_instance;
 
                                mi_static = TypeContainer.FindMembers (
@@ -2224,7 +1950,7 @@ namespace Mono.CSharp {
                                        mi = mi_static;
                                else
                                        mi = null;
-                               
+
                                if (mi != null && mi.Length > 0){
                                        if (!CheckMethodAgainstBase (parent, flags, (MethodInfo) mi [0])){
                                                return false;
@@ -2245,7 +1971,6 @@ namespace Mono.CSharp {
                        //
                        // If we implement an interface, extract the interface name.
                        //
-
                        if (Name.IndexOf (".") != -1){
                                int pos = Name.LastIndexOf (".");
                                iface = Name.Substring (0, pos);
@@ -2258,6 +1983,10 @@ namespace Mono.CSharp {
 
                                // Compute the full name that we need to export
                                Name = iface_type.FullName + "." + short_name;
+
+                               if (!parent.VerifyImplements (iface_type, short_name, Name, Location))
+                                       return false;
+                               
                                explicit_impl = true;
                        } else
                                short_name = Name;
@@ -2266,9 +1995,16 @@ namespace Mono.CSharp {
                        // Check if we are an implementation of an interface method or
                        // a method
                        //
-                       implementing = parent.IsInterfaceMethod (
-                               iface_type, short_name, ret_type, parameters, false);
-                               
+                       if (parent.Pending != null){
+                               implementing = parent.Pending.IsInterfaceMethod (
+                                       iface_type, short_name, ret_type, parameters);
+
+                               if (iface_type != null && implementing == null){
+                                       TypeContainer.Error_ExplicitInterfaceNotMemberInterface (Location, short_name);
+                                       return false;
+                               }
+                       }
+
                        //
                        // For implicit implementations, make sure we are public, for
                        // explicit implementations, make sure we are private.
@@ -2295,11 +2031,8 @@ namespace Mono.CSharp {
                                        if ((ModFlags & Modifiers.STATIC) != 0)
                                                implementing = null;
                                } else {
-                                       if ((ModFlags & (Modifiers.PUBLIC | Modifiers.ABSTRACT)) != 0){
-                                               Report.Error (
-                                                       106, Location, "`public' or `abstract' modifiers "+
-                                                       "are not allowed in explicit interface declarations"
-                                                       );
+                                       if ((ModFlags & (Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
+                                               Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
                                                implementing = null;
                                        }
                                }
@@ -2309,6 +2042,8 @@ namespace Mono.CSharp {
                        // If implementing is still valid, set flags
                        //
                        if (implementing != null){
+                               // Console.WriteLine ("Implementing for:" + (iface_type != null ? iface_type.FullName : "<null>") + " " + short_name);
+                               
                                if (implementing.DeclaringType.IsInterface)
                                        flags |= MethodAttributes.NewSlot;
                                
@@ -2317,10 +2052,10 @@ namespace Mono.CSharp {
                                        MethodAttributes.HideBySig;
 
                                //
-                               // clear the flag
+                               // clear the pending implementation flag
                                //
-                               parent.IsInterfaceMethod (
-                                       iface_type, short_name, ret_type, parameters, true);
+                               parent.Pending.ImplementMethod (
+                                       iface_type, short_name, ret_type, parameters, explicit_impl);
                        } 
 
                        Attribute dllimport_attr = null;
@@ -2430,8 +2165,17 @@ namespace Mono.CSharp {
                        //
                        // abstract or extern methods have no bodies
                        //
-                       if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
+                       if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0){
+                               if (Block != null){
+                                       if ((ModFlags & Modifiers.ABSTRACT) != 0){
+                                               Report.Error (
+                                                       500, "Abstract method `" +
+                                                       TypeManager.CSharpSignature (MethodBuilder) +
+                                                       "' can not have a body");
+                                       }
+                               }
                                return;
+                       }
 
                        //
                        // Handle destructors specially
@@ -2465,7 +2209,6 @@ namespace Mono.CSharp {
                        
                        Label finish = ig.DefineLabel ();
                        bool old_in_try = ec.InTry;
-                       Expression member_lookup;
                        
                        ig.BeginExceptionBlock ();
                        ec.InTry = true;
@@ -2478,15 +2221,17 @@ namespace Mono.CSharp {
                        ec.InFinally = true;
                        ig.BeginFinallyBlock ();
                        
-                       member_lookup = Expression.MemberLookup (
-                               ec, ec.ContainerType.BaseType, "Finalize",
-                               MemberTypes.Method, Expression.AllBindingFlags, Location);
+                       if (ec.ContainerType.BaseType != null) {
+                               Expression member_lookup = Expression.MemberLookup (
+                                       ec, ec.ContainerType.BaseType, "Finalize",
+                                       MemberTypes.Method, Expression.AllBindingFlags, Location);
 
-                       if (member_lookup != null){
-                               MethodGroupExpr parent_destructor = ((MethodGroupExpr) member_lookup);
+                               if (member_lookup != null){
+                                       MethodGroupExpr parent_destructor = ((MethodGroupExpr) member_lookup);
                                
-                               ig.Emit (OpCodes.Ldarg_0);
-                               ig.Emit (OpCodes.Call, (MethodInfo) parent_destructor.Methods [0]);
+                                       ig.Emit (OpCodes.Ldarg_0);
+                                       ig.Emit (OpCodes.Call, (MethodInfo) parent_destructor.Methods [0]);
+                               }
                        }
                        ec.InFinally = old_in_finally;
                        
@@ -2519,18 +2264,23 @@ namespace Mono.CSharp {
                        Type t;
                        
                        if (argument_list != null){
-                               for (int i = argument_list.Count; i > 0; ){
-                                       --i;
-
-                                       Argument a = (Argument) argument_list [i];
+                               foreach (Argument a in argument_list){
                                        if (!a.Resolve (ec, location))
                                                return false;
                                }
                        }
 
-                       if (this is ConstructorBaseInitializer)
+                       if (this is ConstructorBaseInitializer) {
+                               if (ec.ContainerType.BaseType == null)
+                                       return true;
+
                                t = ec.ContainerType.BaseType;
-                       else
+                               if (ec.ContainerType.IsValueType) {
+                                       Report.Error (522, location,
+                                               "structs cannot call base class constructors");
+                                       return false;
+                               }
+                       } else
                                t = ec.ContainerType;
                        
                        parent_constructor_group = Expression.MemberLookup (
@@ -2559,10 +2309,12 @@ namespace Mono.CSharp {
 
                public void Emit (EmitContext ec)
                {
-                       ec.ig.Emit (OpCodes.Ldarg_0);
+                       if (parent_constructor != null)
+                               ec.ig.Emit (OpCodes.Ldarg_0);
                        if (argument_list != null)
                                Invocation.EmitArguments (ec, null, argument_list);
-                       ec.ig.Emit (OpCodes.Call, parent_constructor);
+                       if (parent_constructor != null)
+                               ec.ig.Emit (OpCodes.Call, parent_constructor);
                }
        }
 
@@ -2630,6 +2382,9 @@ namespace Mono.CSharp {
 
                        Type [] parameters = ParameterTypes (parent);
 
+                       if (parameters == null)
+                               return false;
+                       
                        if ((ModFlags & Modifiers.STATIC) != 0)
                                ca |= MethodAttributes.Static;
                        else {
@@ -2675,12 +2430,19 @@ namespace Mono.CSharp {
                        ILGenerator ig = ConstructorBuilder.GetILGenerator ();
                        EmitContext ec = new EmitContext (parent, Location, ig, null, ModFlags, true);
 
-                       if (parent is Class && ((ModFlags & Modifiers.STATIC) == 0)){
-                               if (Initializer == null)
+                       if ((ModFlags & Modifiers.STATIC) == 0){
+                               if (parent is Class && Initializer == null)
                                        Initializer = new ConstructorBaseInitializer (null, parent.Location);
-                               
-                               if (!Initializer.Resolve (ec))
+
+
+                               //
+                               // Spec mandates that Initializers will not have
+                               // `this' access
+                               //
+                               ec.IsStatic = true;
+                               if (Initializer != null && !Initializer.Resolve (ec))
                                        return;
+                               ec.IsStatic = false;
                        }
 
                        LabelParameters (ec, ParameterTypes (parent), ConstructorBuilder);
@@ -2689,11 +2451,11 @@ namespace Mono.CSharp {
                        // Classes can have base initializers and instance field initializers.
                        //
                        if (parent is Class){
-                               if ((ModFlags & Modifiers.STATIC) == 0){
+                               if ((ModFlags & Modifiers.STATIC) == 0)
                                        parent.EmitFieldInitializers (ec);
-                                       Initializer.Emit (ec);
-                               }
                        }
+                       if (Initializer != null)
+                               Initializer.Emit (ec);
                        
                        if ((ModFlags & Modifiers.STATIC) != 0)
                                parent.EmitFieldInitializers (ec);
@@ -2703,9 +2465,13 @@ namespace Mono.CSharp {
                        ec.EmitTopBlock (Block, Location);
                }
        }
-       
-       public class Field : MemberCore {
-               public readonly string Type;
+
+       //
+       // Fields and Events both generate FieldBuilders, we use this to share 
+       // their common bits.  This is also used to flag usage of the field
+       //
+       abstract public class FieldBase : MemberCore {
+               public Expression Type;
                public readonly Object Initializer;
                public readonly Attributes OptAttributes;
                public FieldBuilder  FieldBuilder;
@@ -2714,7 +2480,24 @@ namespace Mono.CSharp {
                [Flags]
                public enum Status : byte { ASSIGNED = 1, USED = 2 }
 
-               
+               //
+               // The constructor is only exposed to our children
+               //
+               protected FieldBase (Expression type, int mod, int allowed_mod, string name,
+                                    object init, Attributes attrs, Location loc)
+                       : base (name, loc)
+               {
+                       Type = type;
+                       ModFlags = Modifiers.Check (allowed_mod, mod, Modifiers.PRIVATE, loc);
+                       Initializer = init;
+                       OptAttributes = attrs;
+               }
+       }
+
+       //
+       // The Field class is used to represents class/struct fields during parsing.
+       //
+       public class Field : FieldBase {
                // <summary>
                //   Modifiers allowed in a class declaration
                // </summary>
@@ -2729,19 +2512,15 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE |
                        Modifiers.READONLY;
 
-               public Field (string type, int mod, string name, Object expr_or_array_init,
+               public Field (Expression type, int mod, string name, Object expr_or_array_init,
                              Attributes attrs, Location loc)
-                       : base (name, loc)
+                       : base (type, mod, AllowedModifiers, name, expr_or_array_init, attrs, loc)
                {
-                       Type = type;
-                       ModFlags = Modifiers.Check (AllowedModifiers, mod, Modifiers.PRIVATE, loc);
-                       Initializer = expr_or_array_init;
-                       OptAttributes = attrs;
                }
 
                public override bool Define (TypeContainer parent)
                {
-                       Type t = RootContext.LookupType (parent, Type, false, Location);
+                       Type t = parent.ResolveType (Type, false, Location);
                        
                        if (t == null)
                                return false;
@@ -2793,7 +2572,7 @@ namespace Mono.CSharp {
                        FieldBuilder = parent.TypeBuilder.DefineField (
                                Name, t, Modifiers.FieldAttr (ModFlags));
 
-                       TypeManager.RegisterField (FieldBuilder, this);
+                       TypeManager.RegisterFieldBase (FieldBuilder, this);
                        return true;
                }
 
@@ -2806,18 +2585,41 @@ namespace Mono.CSharp {
                }
        }
 
+       //
+       // `set' and `get' accessors are represented with an Accessor.
+       // 
+       public class Accessor {
+               //
+               // Null if the accessor is empty, or a Block if not
+               //
+               public Block Block;
+               public Attributes OptAttributes;
+               
+               public Accessor (Block b, Attributes attrs)
+               {
+                       Block = b;
+                       OptAttributes = attrs;
+               }
+       }
+                       
        public class Property : MemberCore {
-               public readonly string Type;
-               public Block           Get, Set;
+               public Expression Type;
+               public Accessor Get, Set;
                public PropertyBuilder PropertyBuilder;
                public Attributes OptAttributes;
                public MethodBuilder GetBuilder, SetBuilder;
 
                //
                // The type, once we compute it.
-               
                Type PropertyType;
 
+               bool explicit_impl;
+
+               //
+               // If true, the interface type we are explicitly implementing
+               //
+               Type explicit_iface_type = null;
+
                const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -2832,7 +2634,8 @@ namespace Mono.CSharp {
                        Modifiers.EXTERN |
                        Modifiers.VIRTUAL;
 
-               public Property (string type, string name, int mod_flags, Block get_block, Block set_block,
+               public Property (Expression type, string name, int mod_flags,
+                                Accessor get_block, Accessor set_block,
                                 Attributes attrs, Location loc)
                        : base (name, loc)
                {
@@ -2907,14 +2710,19 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               bool DefineMethod (TypeContainer parent, Type iface_type, string short_name,
-                                  MethodAttributes flags, bool is_get)
+               bool DefineMethod (TypeContainer parent, string short_name,
+                                  MethodAttributes flags, bool is_get, ref bool is_implementing)
                {
                        Type [] parameters = TypeManager.NoTypes;
-                       MethodInfo implementing;
+                       MethodInfo implementing = null;
                        Type fn_type;
-                       string name;
+                       string name, prefix;
 
+                       if (explicit_impl)
+                               prefix = explicit_iface_type.FullName + ".";
+                       else
+                               prefix = "";
+                               
                        if (is_get){
                                fn_type = PropertyType;
                                name = "get_" + short_name;
@@ -2925,9 +2733,16 @@ namespace Mono.CSharp {
                                fn_type = TypeManager.void_type;
                        }
 
-                       implementing = parent.IsInterfaceMethod (
-                               iface_type, name, fn_type, parameters, false);
+                       if (parent.Pending != null){
+                               implementing = parent.Pending.IsInterfaceMethod (
+                                       explicit_iface_type, name, fn_type, parameters);
 
+                               if (explicit_iface_type != null && implementing == null){
+                                       TypeContainer.Error_ExplicitInterfaceNotMemberInterface (Location, name);
+                                       return false;
+                               }
+                       }
+                       
                        //
                        // For implicit implementations, make sure we are public, for
                        // explicit implementations, make sure we are private.
@@ -2940,7 +2755,7 @@ namespace Mono.CSharp {
                                // The "candidate" function has been flagged already
                                // but it wont get cleared
                                //
-                               if (iface_type == null){
+                               if (explicit_iface_type == null){
                                        //
                                        // We already catch different accessibility settings
                                        // so we just need to check that we are not private
@@ -2954,11 +2769,8 @@ namespace Mono.CSharp {
                                        if ((ModFlags & Modifiers.STATIC) != 0)
                                                implementing = null;
                                } else {
-                                       if ((ModFlags & (Modifiers.PUBLIC | Modifiers.ABSTRACT)) != 0){
-                                               Report.Error (
-                                                       106, Location, "`public' or `abstract' modifiers "+
-                                                       "are not allowed in explicit interface declarations"
-                                                       );
+                                       if ((ModFlags & (Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
+                                               Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
                                                implementing = null;
                                        }
                                }
@@ -2979,10 +2791,12 @@ namespace Mono.CSharp {
                                        MethodAttributes.HideBySig;
 
                                //
-                               // clear the pending flag
+                               // clear the pending implemntation flag
                                //
-                               parent.IsInterfaceMethod (
-                                       iface_type, name, fn_type, parameters, true);
+                               parent.Pending.ImplementMethod (
+                                       explicit_iface_type, name, fn_type, parameters, explicit_impl);
+
+                               is_implementing = true;
                        }
 
                        //
@@ -2995,8 +2809,7 @@ namespace Mono.CSharp {
                        
                        if (is_get){
                                GetBuilder = parent.TypeBuilder.DefineMethod (
-                                       name, flags, PropertyType, null);
-                               PropertyBuilder.SetGetMethod (GetBuilder);
+                                       prefix + name, flags, PropertyType, null);
                        
                                if (implementing != null)
                                        parent.TypeBuilder.DefineMethodOverride (
@@ -3018,14 +2831,13 @@ namespace Mono.CSharp {
                                }
                        } else {
                                SetBuilder = parent.TypeBuilder.DefineMethod (
-                                       name, flags, null, parameters);
+                                       prefix + name, flags, null, parameters);
                                
                                if (implementing != null)
                                        parent.TypeBuilder.DefineMethodOverride (
                                                SetBuilder, implementing);
                                
                                SetBuilder.DefineParameter (1, ParameterAttributes.None, "value"); 
-                               PropertyBuilder.SetSetMethod (SetBuilder);
 
                                //
                                // HACK because System.Reflection.Emit is lame
@@ -3051,7 +2863,6 @@ namespace Mono.CSharp {
 
                public override bool Define (TypeContainer parent)
                {
-                       Type iface_type = null;
                        string short_name;
                        
                        if (!parent.MethodModifiersValid (ModFlags, Name, Location))
@@ -3059,11 +2870,10 @@ namespace Mono.CSharp {
 
                        MethodAttributes flags = Modifiers.MethodAttr (ModFlags);
                        
-                       flags |= MethodAttributes.HideBySig |
-                               MethodAttributes.SpecialName;
+                       flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
                        // Lookup Type, verify validity
-                       PropertyType = RootContext.LookupType (parent, Type, false, Location);
+                       PropertyType = parent.ResolveType (Type, false, Location);
                        if (PropertyType == null)
                                return false;
 
@@ -3084,45 +2894,61 @@ namespace Mono.CSharp {
                                int pos = Name.LastIndexOf (".");
                                string iface = Name.Substring (0, pos);
 
-                               iface_type = RootContext.LookupType (parent, iface, false, Location);
-                               if (iface_type == null)
+                               explicit_iface_type = RootContext.LookupType (parent, iface, false, Location);
+                               if (explicit_iface_type == null)
                                        return false;
 
                                short_name = Name.Substring (pos + 1);
 
                                // Compute the full name that we need to export.
-                               Name = iface_type.FullName + "." + short_name;
-                       } else
+                               Name = explicit_iface_type.FullName + "." + short_name;
+                               
+                               if (!parent.VerifyImplements (explicit_iface_type, short_name, Name, Location))
+                                       return false;
+                               
+                               explicit_impl = true;
+                       } else {
+                               explicit_impl = false;
                                short_name = Name;
+                       }
 
-                       // FIXME - PropertyAttributes.HasDefault ?
-
-                       PropertyAttributes prop_attr = PropertyAttributes.RTSpecialName |
-                                                      PropertyAttributes.SpecialName;
-               
-                       PropertyBuilder = parent.TypeBuilder.DefineProperty (
-                               Name, prop_attr, PropertyType, null);
-
+                       bool is_implementing = false;
                        if (Get != null)
-                               if (!DefineMethod (parent, iface_type, short_name, flags, true))
+                               if (!DefineMethod (parent, short_name, flags, true, ref is_implementing))
                                        return false;
                        
                        if (Set != null)
-                               if (!DefineMethod (parent, iface_type, short_name, flags, false))
+                               if (!DefineMethod (parent, short_name, flags, false, ref is_implementing))
                                        return false;
+
+                       // FIXME - PropertyAttributes.HasDefault ?
                        
-                       //
-                       // HACK for the reasons exposed above
-                       //
-                       if (!TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder)) {
-                               Report.Error (
-                                       111, Location,
-                                       "Class `" + parent.Name +
-                                       "' already contains a definition for the property `" +
-                                       Name + "'");
-                               return false;
-                       }
+                       PropertyAttributes prop_attr =
+                       PropertyAttributes.RTSpecialName |
+                       PropertyAttributes.SpecialName;
+
+                       if (!explicit_impl){
+                               PropertyBuilder = parent.TypeBuilder.DefineProperty (
+                                       Name, prop_attr, PropertyType, null);
+                               
+                               if (Get != null)
+                                       PropertyBuilder.SetGetMethod (GetBuilder);
+                               
+                               if (Set != null)
+                                       PropertyBuilder.SetSetMethod (SetBuilder);
 
+                               //
+                               // HACK for the reasons exposed above
+                               //
+                               if (!TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder)) {
+                                       Report.Error (
+                                               111, Location,
+                                               "Class `" + parent.Name +
+                                               "' already contains a definition for the property `" +
+                                               Name + "'");
+                                       return false;
+                               }
+                       }
                        return true;
                }
                
@@ -3132,8 +2958,18 @@ namespace Mono.CSharp {
                        EmitContext ec;
 
                        ec = new EmitContext (tc, Location, null, PropertyType, ModFlags);
-                       Attribute.ApplyAttributes (ec, PropertyBuilder, this, OptAttributes, Location);
-                       
+
+                       //
+                       // 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 (Get != null)
+                               Attribute.ApplyAttributes (ec, GetBuilder, Get, Get.OptAttributes, Location);
+                       if (Set != null)
+                               Attribute.ApplyAttributes (ec, SetBuilder, Set, Set.OptAttributes, Location);
 
                        //
                        // abstract or extern properties have no bodies
@@ -3144,15 +2980,15 @@ namespace Mono.CSharp {
                        if (Get != null){
                                ig = GetBuilder.GetILGenerator ();
                                ec = new EmitContext (tc, Location, ig, PropertyType, ModFlags);
-                               
-                               ec.EmitTopBlock (Get, Location);
+
+                               ec.EmitTopBlock (Get.Block, Location);
                        }
 
                        if (Set != null){
                                ig = SetBuilder.GetILGenerator ();
                                ec = new EmitContext (tc, Location, ig, null, ModFlags);
-                               
-                               ec.EmitTopBlock (Set, Location);
+
+                               ec.EmitTopBlock (Set.Block, Location);
                        }
                }
        }
@@ -3189,9 +3025,7 @@ namespace Mono.CSharp {
                        
                        declaring_type = type_builder;
 
-                       // FIXME : This is supposed to be MyBuilder but since that doesn't
-                       // derive from Type, I have no clue what to do with this.
-                       reflected_type = null;
+                       reflected_type = type_builder;
                        
                        attributes = event_attr;
                        this.name = name;
@@ -3295,8 +3129,7 @@ namespace Mono.CSharp {
                }
        }
        
-       public class Event : MemberCore {
-               
+       public class Event : FieldBase {
                const int AllowedModifiers =
                        Modifiers.NEW |
                        Modifiers.PUBLIC |
@@ -3310,28 +3143,19 @@ namespace Mono.CSharp {
                        Modifiers.UNSAFE |
                        Modifiers.ABSTRACT;
 
-               public readonly string    Type;
-               public readonly Object    Initializer;
-               public readonly Block     Add;
-               public readonly Block     Remove;
+               public readonly Accessor  Add;
+               public readonly Accessor  Remove;
                public MyEventBuilder     EventBuilder;
-               public FieldBuilder       FieldBuilder;
-               public Attributes         OptAttributes;
 
                Type EventType;
                MethodBuilder AddBuilder, RemoveBuilder;
                
-
-               public Event (string type, string name, Object init, int flags, Block add_block,
-                             Block rem_block, Attributes attrs, Location loc)
-                       : base (name, loc)
+               public Event (Expression type, string name, Object init, int mod, Accessor add,
+                             Accessor remove, Attributes attrs, Location loc)
+                       : base (type, mod, AllowedModifiers, name, init, attrs, loc)
                {
-                       Type = type;
-                       Initializer = init;
-                       ModFlags = Modifiers.Check (AllowedModifiers, flags, Modifiers.PRIVATE, loc);  
-                       Add = add_block;
-                       Remove = rem_block;
-                       OptAttributes = attrs;
+                       Add = add;
+                       Remove = remove;
                }
 
                public override bool Define (TypeContainer parent)
@@ -3342,7 +3166,7 @@ namespace Mono.CSharp {
                        MethodAttributes m_attr = Modifiers.MethodAttr (ModFlags);
                        EventAttributes e_attr = EventAttributes.RTSpecialName | EventAttributes.SpecialName;
 
-                       EventType = RootContext.LookupType (parent, Type, false, Location);
+                       EventType = parent.ResolveType (Type, false, Location);
                        if (EventType == null)
                                return false;
 
@@ -3363,18 +3187,25 @@ namespace Mono.CSharp {
 
                        EventBuilder = new MyEventBuilder (parent.TypeBuilder, Name, e_attr, EventType);
 
-                       if (Add == null && Remove == null)
-                               FieldBuilder = parent.TypeBuilder.DefineField (Name, EventType, FieldAttributes.Private);
+                       if (Add == null && Remove == null) {
+                               FieldBuilder = parent.TypeBuilder.DefineField (
+                                       Name, EventType, FieldAttributes.FamANDAssem);
+                               TypeManager.RegisterPrivateFieldOfEvent ((EventInfo) EventBuilder, FieldBuilder);
+                               TypeManager.RegisterFieldBase (FieldBuilder, this);
+                       }
                        
                        //
                        // Now define the accessors
                        //
+                       string add_name = "add_" + Name;
                        
                        AddBuilder = parent.TypeBuilder.DefineMethod (
-                                                        "add_" + Name, m_attr, null, parameters);
+                               add_name, m_attr, null, parameters);
                        AddBuilder.DefineParameter (1, ParameterAttributes.None, "value");
                        EventBuilder.SetAddOnMethod (AddBuilder);
-
+                       if (parent.Pending != null)
+                               parent.Pending.ImplementMethod (null, add_name, null, parameters, false);
+                       
                        //
                        // HACK because System.Reflection.Emit is lame
                        //
@@ -3390,11 +3221,20 @@ namespace Mono.CSharp {
                                              "'add' method of event `" + Name + "'");
                                return false;
                        }
-               
+
+                       string remove_name = "remove_" + Name;
                        RemoveBuilder = parent.TypeBuilder.DefineMethod (
-                                                           "remove_" + Name, m_attr, null, parameters);
+                               remove_name, m_attr, null, parameters);
                        RemoveBuilder.DefineParameter (1, ParameterAttributes.None, "value");
                        EventBuilder.SetRemoveOnMethod (RemoveBuilder);
+                       if (parent.Pending != null)
+                               parent.Pending.ImplementMethod (null, remove_name, null, parameters, false);
+
+                       //
+                       // This looks like dead code
+                       //
+                       //if (parent.Pending != null)
+                       // parent.Pending.IsInterfaceMethod (null, remove_name, null, parameters, false);
 
                        //
                        // HACK because System.Reflection.Emit is lame
@@ -3447,17 +3287,19 @@ namespace Mono.CSharp {
                        ig = AddBuilder.GetILGenerator ();
                        ec = new EmitContext (tc, Location, ig, TypeManager.void_type, ModFlags);
 
-                       if (Add != null)
-                               ec.EmitTopBlock (Add, Location);
-                       else
+                       if (Add != null) {
+                               Attribute.ApplyAttributes (ec, AddBuilder, Add, Add.OptAttributes, Location);
+                               ec.EmitTopBlock (Add.Block, Location);
+                       } else
                                EmitDefaultMethod (ec, true);
 
                        ig = RemoveBuilder.GetILGenerator ();
                        ec = new EmitContext (tc, Location, ig, TypeManager.void_type, ModFlags);
                        
-                       if (Remove != null)
-                               ec.EmitTopBlock (Remove, Location);
-                       else
+                       if (Remove != null) {
+                               Attribute.ApplyAttributes (ec, RemoveBuilder, Remove, Remove.OptAttributes, Location);
+                               ec.EmitTopBlock (Remove.Block, Location);
+                       } else
                                EmitDefaultMethod (ec, false);
 
                        ec = new EmitContext (tc, Location, null, EventType, ModFlags);
@@ -3471,6 +3313,7 @@ namespace Mono.CSharp {
        // FIXME: This does not handle:
        //
        //   int INTERFACENAME [ args ]
+       //   Does not 
        //
        // Only:
        // 
@@ -3491,19 +3334,21 @@ namespace Mono.CSharp {
                        Modifiers.EXTERN |
                        Modifiers.ABSTRACT;
 
-               public readonly string     Type;
+               public readonly Expression Type;
                public readonly string     InterfaceType;
                public readonly Parameters FormalParameters;
-               public readonly Block      Get;
-               public readonly Block      Set;
+               public readonly Accessor   Get, Set;
                public Attributes          OptAttributes;
                public MethodBuilder       GetBuilder;
                public MethodBuilder       SetBuilder;
                public PropertyBuilder PropertyBuilder;
                public Type IndexerType;
-
-               public Indexer (string type, string int_type, int flags, Parameters parms,
-                               Block get_block, Block set_block, Attributes attrs, Location loc)
+               public string IndexerName;
+               
+               EmitContext ec;
+               
+               public Indexer (Expression type, string int_type, int flags, Parameters parms,
+                               Accessor get_block, Accessor set_block, Attributes attrs, Location loc)
                        : base ("", loc)
                {
 
@@ -3516,15 +3361,25 @@ namespace Mono.CSharp {
                        OptAttributes = attrs;
                }
 
-               void DefineMethod (TypeContainer parent, Type iface_type, 
+               bool DefineMethod (TypeContainer parent, Type explicit_iface_type, 
                                   Type ret_type, string name,
                                   Type [] parameters, MethodAttributes attr, bool is_get)
                {
-                       MethodInfo implementing;
+                       MethodInfo implementing = null;
+                       bool is_implementation;
 
-                       implementing = parent.IsInterfaceMethod (
-                               iface_type, name, ret_type, parameters, false);
+                       if (parent.Pending != null){
+                               implementing = parent.Pending.IsInterfaceMethod (
+                                       explicit_iface_type, name, ret_type, parameters);
+
+                               if (explicit_iface_type != null && implementing == null){
+                                       TypeContainer.Error_ExplicitInterfaceNotMemberInterface (Location, "this");
+                                       return false;
+                               }
+                       }
 
+                       is_implementation = implementing != null;
+                       
                        //
                        // Setting null inside this block will trigger a more
                        // verbose error reporting for missing interface implementations
@@ -3533,7 +3388,7 @@ namespace Mono.CSharp {
                        // but it wont get cleared
                        //
                        if (implementing != null){
-                               if (iface_type == null){
+                               if (explicit_iface_type == null){
                                        //
                                        // We already catch different accessibility settings
                                        // so we just need to check that we are not private
@@ -3547,12 +3402,8 @@ namespace Mono.CSharp {
                                        if ((ModFlags & Modifiers.STATIC) != 0)
                                                implementing = null;
                                } else {
-                                       if((ModFlags&(Modifiers.PUBLIC | Modifiers.ABSTRACT)) != 0){
-                                               Report.Error (
-                                                       106, Location,
-                                                       "`public' or `abstract' modifiers are not "+
-                                                       "allowed in explicit interface declarations"
-                                                       );
+                                       if((ModFlags&(Modifiers.PUBLIC | Modifiers.ABSTRACT | Modifiers.VIRTUAL)) != 0){
+                                               Modifiers.Error_InvalidModifier (Location, "public, virtual or abstract");
                                                implementing = null;
                                        }
                                }
@@ -3569,10 +3420,10 @@ namespace Mono.CSharp {
                                        MethodAttributes.HideBySig;
 
                                //
-                               // clear the pending flag
+                               // clear the pending implementing flag
                                //
-                               parent.IsInterfaceMethod (
-                                       iface_type, name, ret_type, parameters, true);
+                               parent.Pending.ImplementMethod (
+                                       explicit_iface_type, name, ret_type, parameters, true);
                        }
 
                        //
@@ -3580,14 +3431,17 @@ namespace Mono.CSharp {
                        // clear implementing, as it is only used for explicit
                        // interface implementation
                        //
-                       if (Name.IndexOf (".") == -1)
+                       if (InterfaceType == null)
                                implementing = null;
 
+                       string prefix;
+                       if (explicit_iface_type == null)
+                               prefix = "";
+                       else
+                               prefix = explicit_iface_type.FullName + ".";
+                       
                        if (is_get){
-
-                               string meth_name = "get_Item";
-                               if (iface_type != null)
-                                       meth_name = iface_type + ".get_Item";
+                               string meth_name = prefix + "get_" + IndexerName;
                                
                                GetBuilder = parent.TypeBuilder.DefineMethod (
                                        meth_name, attr, IndexerType, parameters);
@@ -3595,24 +3449,17 @@ namespace Mono.CSharp {
                                if (implementing != null) 
                                        parent.TypeBuilder.DefineMethodOverride (
                                                GetBuilder, implementing);
-                               
-                               
-                               PropertyBuilder.SetGetMethod (GetBuilder);
                        } else {
+                               string meth_name = prefix + "set_" + IndexerName;
 
-                               string meth_name = "set_Item";
-
-                               if (iface_type != null)
-                                       meth_name = iface_type + ".set_Item";
-                               
                                SetBuilder = parent.TypeBuilder.DefineMethod (
                                        meth_name, attr, null, parameters);
                                if (implementing != null)
                                        parent.TypeBuilder.DefineMethodOverride (
                                                SetBuilder, implementing);
-                                       
-                               PropertyBuilder.SetSetMethod (SetBuilder);
                        }
+
+                       return is_implementation;
                }
                        
                public override bool Define (TypeContainer parent)
@@ -3622,7 +3469,7 @@ namespace Mono.CSharp {
                                PropertyAttributes.SpecialName;
                        bool error = false;
                        
-                       IndexerType = RootContext.LookupType (parent, Type, false, Location);
+                       IndexerType = parent.ResolveType (Type, false, Location);
                        Type [] parameters = FormalParameters.GetParameterInfo (parent);
 
                        // Check if the return type and arguments were correct
@@ -3652,24 +3499,31 @@ namespace Mono.CSharp {
                        if (error)
                                return false;
                        
-                       Type iface_type = null;
+                       Type explicit_iface_type = null;
 
                        if (InterfaceType != null){
-                               iface_type = RootContext.LookupType (parent, InterfaceType, false, Location);
-                               if (iface_type == null)
+                               explicit_iface_type = RootContext.LookupType (parent, InterfaceType, false, Location);
+                               if (explicit_iface_type == null)
+                                       return false;
+
+                               if (!parent.VerifyImplements (explicit_iface_type, "this", "this", Location))
                                        return false;
                        } 
-                               
-                       
-                       PropertyBuilder = parent.TypeBuilder.DefineProperty (
-                               TypeManager.IndexerPropertyName (parent.TypeBuilder),
-                               prop_attr, IndexerType, parameters);
 
+                       ec = new EmitContext (parent, Location, null, IndexerType, ModFlags);
+
+                       IndexerName = Attribute.ScanForIndexerName (ec, OptAttributes);
+                       if (IndexerName == null)
+                               IndexerName = "Item";
+                       
                        MethodAttributes attr = Modifiers.MethodAttr (ModFlags);
+
+                       bool is_implementing = false;
                        
                        if (Get != null){
-                               DefineMethod (parent, iface_type, IndexerType, "get_Item",
-                                             parameters, attr, true);
+                               is_implementing = DefineMethod (
+                                       parent, explicit_iface_type, IndexerType, "get_" + IndexerName,
+                                       parameters, attr, true);
                                 InternalParameters pi = new InternalParameters (parent, FormalParameters);
                                if (!TypeManager.RegisterMethod (GetBuilder, pi, parameters)) {
                                        Report.Error (111, Location,
@@ -3689,17 +3543,34 @@ namespace Mono.CSharp {
 
                                Parameter [] fixed_parms = FormalParameters.FixedParameters;
 
+                               if (fixed_parms == null){
+                                       throw new Exception ("We currently do not support only array arguments in an indexer");
+                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+                                       //
+                                       // Here is the problem: the `value' parameter has
+                                       // to come *after* the array parameter in the declaration
+                                       // like this:
+                                       // X (object [] x, Type value)
+                                       // .param [0]
+                                       //
+                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+                                       // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG
+                                       
+                               }
+                               
                                Parameter [] tmp = new Parameter [fixed_parms.Length + 1];
 
+
                                fixed_parms.CopyTo (tmp, 0);
                                tmp [fixed_parms.Length] = new Parameter (
                                        Type, "value", Parameter.Modifier.NONE, null);
 
                                Parameters set_formal_params = new Parameters (tmp, null, Location);
                                
-                               DefineMethod (
-                                       parent, iface_type, TypeManager.void_type,
-                                       "set_Item", set_pars, attr, false);
+                               is_implementing = DefineMethod (
+                                       parent, explicit_iface_type, TypeManager.void_type,
+                                       "set_" + IndexerName, set_pars, attr, false);
 
                                InternalParameters ip = new InternalParameters (parent, set_formal_params);
                                
@@ -3742,7 +3613,23 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder);
+
+                       //
+                       // Only define the PropertyBuilder if we are not implementing
+                       // an interface property.
+                       //
+                       if (!is_implementing){
+                               PropertyBuilder = parent.TypeBuilder.DefineProperty (
+                                       IndexerName, prop_attr, IndexerType, parameters);
+
+                               if (GetBuilder != null)
+                                       PropertyBuilder.SetGetMethod (GetBuilder);
+
+                               if (SetBuilder != null)
+                                       PropertyBuilder.SetSetMethod (SetBuilder);
+                               
+                               TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder);
+                       }
 
                        return true;
                }
@@ -3750,23 +3637,35 @@ namespace Mono.CSharp {
                public void Emit (TypeContainer tc)
                {
                        ILGenerator ig;
-                       EmitContext ec;
 
-                       ec = new EmitContext (tc, Location, null, IndexerType, ModFlags);
-                       Attribute.ApplyAttributes (ec, PropertyBuilder, this, OptAttributes, Location);
+                       //
+                       // 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 (Get != null)
+                               Attribute.ApplyAttributes (ec, GetBuilder, Get, Get.OptAttributes, Location);
+                       if (Set != null)
+                               Attribute.ApplyAttributes (ec, SetBuilder, Set, Set.OptAttributes, Location);
 
+                       if ((ModFlags & (Modifiers.ABSTRACT | Modifiers.EXTERN)) != 0)
+                               return;
+                       
                        if (Get != null){
                                ig = GetBuilder.GetILGenerator ();
                                ec = new EmitContext (tc, Location, ig, IndexerType, ModFlags);
                                
-                               ec.EmitTopBlock (Get, Location);
+                               ec.EmitTopBlock (Get.Block, Location);
                        }
 
                        if (Set != null){
                                ig = SetBuilder.GetILGenerator ();
                                ec = new EmitContext (tc, Location, ig, null, ModFlags);
                                
-                               ec.EmitTopBlock (Set, Location);
+                               ec.EmitTopBlock (Set.Block, Location);
                        }
                }
        }
@@ -3822,11 +3721,9 @@ namespace Mono.CSharp {
                };
 
                public readonly OpType OperatorType;
-               public readonly string ReturnType;
-               public readonly string FirstArgType;
-               public readonly string FirstArgName;
-               public readonly string SecondArgType;
-               public readonly string SecondArgName;
+               public readonly Expression ReturnType;
+               public readonly Expression FirstArgType, SecondArgType;
+               public readonly string FirstArgName, SecondArgName;
                public readonly Block  Block;
                public Attributes      OptAttributes;
                public MethodBuilder   OperatorMethodBuilder;
@@ -3834,8 +3731,10 @@ namespace Mono.CSharp {
                public string MethodName;
                public Method OperatorMethod;
 
-               public Operator (OpType type, string ret_type, int flags, string arg1type, string arg1name,
-                                string arg2type, string arg2name, Block block, Attributes attrs, Location loc)
+               public Operator (OpType type, Expression ret_type, int flags,
+                                Expression arg1type, string arg1name,
+                                Expression arg2type, string arg2name,
+                                Block block, Attributes attrs, Location loc)
                        : base ("", loc)
                {
                        OperatorType = type;
@@ -4094,8 +3993,13 @@ namespace Mono.CSharp {
                        
                        mi = (MethodInfo) m;
 
-                       if (mi.ReturnType != sig.RetType)
-                               return false;
+                       //
+                       // we use sig.RetType == null to mean `do not check the
+                       // method return value.  
+                       //
+                       if (sig.RetType != null)
+                               if (mi.ReturnType != sig.RetType)
+                                       return false;
 
                        Type [] args = TypeManager.GetArgumentTypes (mi);
                        Type [] sigp = sig.Parameters;
@@ -4113,7 +4017,13 @@ namespace Mono.CSharp {
 
                //
                // This filter should be used when we are requesting methods that
-               // we want to override.  
+               // 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 InheritableMemberSignatureCompare (MemberInfo m, object filter_criteria)
                {
@@ -4128,7 +4038,7 @@ namespace Mono.CSharp {
                                // If only accessible to the defining assembly or 
                                if (prot == MethodAttributes.FamANDAssem ||
                                    prot == MethodAttributes.Assembly){
-                                       if (m is MethodBuilder)
+                                       if (m.DeclaringType.Assembly == CodeGen.AssemblyBuilder)
                                                return true;
                                        else
                                                return false;