**** Merged from MCS ****
[mono.git] / mcs / gmcs / class.cs
index af605bb94cffa58d6ea31cde76d13900696b8aab..b851ffec290552c2af646ae706bfc50f7fce1428 100755 (executable)
@@ -119,7 +119,7 @@ namespace Mono.CSharp {
                        {
                                base.DefineContainerMembers ();
  
-                               if (HasEquals && !HasGetHashCode) {
+                               if ((RootContext.WarningLevel >= 3) && HasEquals && !HasGetHashCode) {
                                        Report.Warning (659, container.Location, "'{0}' overrides Object.Equals(object) but does not override Object.GetHashCode()", container.GetSignatureForError ());
                                }
                        }
@@ -174,11 +174,11 @@ namespace Mono.CSharp {
                                        seen_normal_indexers = true;
 
                                        if (class_indexer_name == null) {
-                                               class_indexer_name = i.IndexerName;
+                                               class_indexer_name = i.ShortName;
                                                continue;
                                        }
 
-                                       if (i.IndexerName != class_indexer_name)
+                                       if (i.ShortName != class_indexer_name)
                                                Report.Error (668, i.Location, "Two indexers have different names; the IndexerName attribute must be used with the same name on every indexer within a type");
                                }
 
@@ -222,7 +222,7 @@ namespace Mono.CSharp {
                                {
                                        flags = f;
 
-                                       ret_type = o.OperatorMethod.GetReturnType ();
+                                       ret_type = o.OperatorMethod.ReturnType;
                                        Type [] pt = o.OperatorMethod.ParameterTypes;
                                        type1 = pt [0];
                                        type2 = pt [1];
@@ -350,11 +350,11 @@ namespace Mono.CSharp {
                                                        "The operator `" + oe.op + "' requires a matching operator `" + s + "' to also be defined");
                                }
 
-                               if (has_equality_or_inequality && container.Methods == null && (RootContext.WarningLevel > 2)) {
-                                       if (!container.Methods.HasEquals)
+                               if (has_equality_or_inequality && (RootContext.WarningLevel > 2)) {
+                                       if (container.Methods == null || !container.Methods.HasEquals)
                                                Report.Warning (660, container.Location, "'{0}' defines operator == or operator != but does not override Object.Equals(object o)", container.GetSignatureForError ());
  
-                                       if (!container.Methods.HasGetHashCode)
+                                       if (container.Methods == null || !container.Methods.HasGetHashCode)
                                                Report.Warning (661, container.Location, "'{0}' defines operator == or operator != but does not override Object.GetHashCode()", container.GetSignatureForError ());
                                }
                        }
@@ -383,16 +383,16 @@ namespace Mono.CSharp {
                MemberCoreArrayList delegates;
                
                // Holds the list of constructors
-               MemberCoreArrayList instance_constructors;
+               protected MemberCoreArrayList instance_constructors;
 
                // Holds the list of fields
                MemberCoreArrayList fields;
 
                // Holds a list of fields that have initializers
-               ArrayList initialized_fields;
+               protected ArrayList initialized_fields;
 
                // Holds a list of static fields that have initializers
-               ArrayList initialized_static_fields;
+               protected ArrayList initialized_static_fields;
 
                // Holds the list of constants
                MemberCoreArrayList constants;
@@ -424,13 +424,8 @@ namespace Mono.CSharp {
                //
                // Pointers to the default constructor and the default static constructor
                //
-               Constructor default_constructor;
-               Constructor default_static_constructor;
-
-               //
-               // Whether we have seen a static constructor for this class or not
-               //
-               public bool UserDefinedStaticConstructor = false;
+               protected Constructor default_constructor;
+               protected Constructor default_static_constructor;
 
                //
                // Whether we have at least one non-static field
@@ -441,8 +436,8 @@ namespace Mono.CSharp {
                // This one is computed after we can distinguish interfaces
                // from classes from the arraylist `type_bases' 
                //
-               string     base_class_name;
-               TypeExpr   parent_type;
+               string base_class_name;
+               TypeExpr parent_type;
 
                ArrayList type_bases;
 
@@ -450,7 +445,8 @@ namespace Mono.CSharp {
                bool members_defined_ok;
 
                // The interfaces we implement.
-               Type[] ifaces;
+               protected Type[] ifaces;
+               protected Type ptype;
 
                // The parent member container and our member cache
                IMemberContainer parent_container;
@@ -460,8 +456,8 @@ namespace Mono.CSharp {
 
                Type GenericType;
 
-               public TypeContainer (NamespaceEntry ns, TypeContainer parent,
-                                     MemberName name, Attributes attrs, Kind kind, Location l)
+               public TypeContainer (NamespaceEntry ns, TypeContainer parent, MemberName name,
+                                     Attributes attrs, Kind kind, Location l)
                        : base (ns, parent, name, attrs, l)
                {
                        this.Kind = kind;
@@ -471,140 +467,61 @@ namespace Mono.CSharp {
                        base_class_name = null;
                }
 
-               // <summary>
-               //   Used to report back to the user the result of a declaration
-               //   in the current declaration space
-               // </summary>
-               public void CheckDef (AdditionResult result, string name, Location loc)
+               public bool AddToMemberContainer (MemberCore symbol, bool is_method)
                {
-                       if (result == AdditionResult.Success)
-                               return;
-
-                       switch (result){
-                       case AdditionResult.NameExists:
-                               Report.Error (102, loc, "The container `{0}' already " +
-                                             "contains a definition for `{1}'",
-                                             Name, name);
-                               break;
-
-                               //
-                               // This is handled only for static Constructors, because
-                               // in reality we handle these by the semantic analysis later
-                               //
-                       case AdditionResult.MethodExists:
-                               Report.Error (111, loc, "Class `{0}' already defines a " +
-                                             "member called '{1}' with the same parameter " +
-                                             "types (more than one default constructor)",
-                                             Name, name);
-                               break;
-
-                       case AdditionResult.EnclosingClash:
-                               Report.Error (542, loc, "Member names cannot be the same " +
-                                             "as their enclosing type");
-                               break;
-               
-                       case AdditionResult.NotAConstructor:
-                               Report.Error (1520, loc, "Class, struct, or interface method " +
-                                             "must have a return type");
-                               break;
+                       return AddToContainer (symbol, is_method, String.Concat (Name, '.', symbol.Name), symbol.Name);
+               }
 
-                       case AdditionResult.Error:
-                               // Error has already been reported.
-                               break;
-                       }
+               bool AddToTypeContainer (DeclSpace ds)
+               {
+                       return AddToContainer (ds, false, ds.Name, ds.Basename);
                }
 
-               public AdditionResult AddConstant (Const constant)
+               public void AddConstant (Const constant)
                {
-                       AdditionResult res;
-                       string basename = constant.Name;
-                       string fullname = Name + "." + basename;
+                       if (!AddToMemberContainer (constant, false))
+                               return;
 
-                       if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
-                               return res;
-                       
                        if (constants == null)
                                constants = new MemberCoreArrayList ();
 
                        constants.Add (constant);
-                       DefineName (fullname, constant);
-
-                       return AdditionResult.Success;
                }
 
-               public AdditionResult AddEnum (Mono.CSharp.Enum e)
+               public void AddEnum (Mono.CSharp.Enum e)
                {
-                       AdditionResult res;
-
-                       if ((res = IsValid (e.Basename, e.Name)) != AdditionResult.Success)
-                               return res;
+                       if (!AddToTypeContainer (e))
+                               return;
 
                        if (enums == null)
                                enums = new MemberCoreArrayList ();
 
                        enums.Add (e);
-                       DefineName (e.Name, e);
-
-                       return AdditionResult.Success;
                }
                
-               public AdditionResult AddClass (TypeContainer c)
+               public void AddClassOrStruct (TypeContainer c)
                {
-                       AdditionResult res;
-                       string name = c.Basename;
-                       
-                       if ((res = IsValid (name, c.Name)) != AdditionResult.Success)
-                               return res;
+                       if (!AddToTypeContainer (c))
+                               return;
 
-                       DefineName (c.Name, c);
                        types.Add (c);
-
-                       return AdditionResult.Success;
-               }
-
-               public AdditionResult AddStruct (TypeContainer s)
-               {
-                       AdditionResult res;
-                       string name = s.Basename;
-                       
-                       if ((res = IsValid (name, s.Name)) != AdditionResult.Success)
-                               return res;
-
-                       DefineName (s.Name, s);
-                       types.Add (s);
-
-                       return AdditionResult.Success;
                }
 
-               public AdditionResult AddDelegate (Delegate d)
+               public void AddDelegate (Delegate d)
                {
-                       AdditionResult res;
-                       string name = d.Basename;
-                       
-                       if ((res = IsValid (name, d.Name)) != AdditionResult.Success)
-                               return res;
+                       if (!AddToTypeContainer (d))
+                               return;
 
                        if (delegates == null)
                                delegates = new MemberCoreArrayList ();
                        
-                       DefineName (d.Name, d);
                        delegates.Add (d);
-
-                       return AdditionResult.Success;
                }
 
-               public AdditionResult AddMethod (Method method)
+               public void AddMethod (Method method)
                {
-                       string basename = method.Name;
-                       string fullname = Name + "." + basename;
-
-                       Object value = defined_names [fullname];
-
-                       if (value != null && (!(value is Method)))
-                               return AdditionResult.NameExists;
-
-                       if (basename == Basename)
-                               return AdditionResult.EnclosingClash;
+                       if (!AddToMemberContainer (method, true))
+                               return;
 
                        if (methods == null)
                                methods = new MethodArrayList (this);
@@ -613,30 +530,33 @@ namespace Mono.CSharp {
                                methods.Insert (0, method);
                        else 
                                methods.Add (method);
-                       
-                       if (value == null)
-                               DefineName (fullname, method);
-
-                       return AdditionResult.Success;
                }
 
-               public AdditionResult AddConstructor (Constructor c)
+               public void AddConstructor (Constructor c)
                {
-                       if (c.Name != Basename) 
-                               return AdditionResult.NotAConstructor;
+                       if (c.Name != Basename) {
+                               Report.Error (1520, Location, "Class, struct, or interface method must have a return type");
+                       }
 
                        bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
                        
                        if (is_static){
-                               UserDefinedStaticConstructor = true;
-                               if (default_static_constructor != null)
-                                       return AdditionResult.MethodExists;
+                               if (default_static_constructor != null) {
+                                       Report.SymbolRelatedToPreviousError (default_static_constructor);
+                                       Report.Error (111, c.Location, "Type '{0}' already defines a member " +
+                                                     "called '{1}' with the same parameter types", Name, c.Name);
+                                       return;
+                               }
 
                                default_static_constructor = c;
                        } else {
                                if (c.IsDefault ()){
-                                       if (default_constructor != null)
-                                               return AdditionResult.MethodExists;
+                                       if (default_constructor != null) {
+                                               Report.SymbolRelatedToPreviousError (default_constructor);
+                                               Report.Error (111, c.Location, "Type '{0}' already defines a member " +
+                                                     "called '{1}' with the same parameter types", Name, c.Name);
+                                               return;
+                                       }
                                        default_constructor = c;
                                }
                                
@@ -645,35 +565,25 @@ namespace Mono.CSharp {
                                
                                instance_constructors.Add (c);
                        }
-                       
-                       return AdditionResult.Success;
                }
                
-               public AdditionResult AddInterface (TypeContainer iface)
+               public void AddInterface (TypeContainer iface)
                {
-                       AdditionResult res;
-                       string name = iface.Basename;
-                       
-                       if ((res = IsValid (name, iface.Name)) != AdditionResult.Success)
-                               return res;
-                       
-                       if (interfaces == null)
+                       if (!AddToTypeContainer (iface))
+                               return;
+
+                       if (interfaces == null) {
                                interfaces = new MemberCoreArrayList ();
+                       }
+
                        interfaces.Add (iface);
-                       DefineName (iface.Name, iface);
-                       
-                       return AdditionResult.Success;
                }
 
-               public AdditionResult AddField (Field field)
+               public void AddField (Field field)
                {
-                       AdditionResult res;
-                       string basename = field.Name;
-                       string fullname = Name + "." + basename;
+                       if (!AddToMemberContainer (field, false))
+                               return;
 
-                       if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
-                               return res;
-                       
                        if (fields == null)
                                fields = new MemberCoreArrayList ();
                        
@@ -696,27 +606,13 @@ namespace Mono.CSharp {
 
                        if ((field.ModFlags & Modifiers.STATIC) == 0)
                                have_nonstatic_fields = true;
-
-                       DefineName (fullname, field);
-                       return AdditionResult.Success;
                }
 
-               public AdditionResult AddProperty (Property prop)
+               public void AddProperty (Property prop)
                {
-                       AdditionResult res;
-
-                       if ((res = AddProperty (prop, prop.Name)) != AdditionResult.Success)
-                               return res;
-
-                       if (prop.Get != null) {
-                               if ((res = AddProperty (prop, "get_" + prop.Name)) != AdditionResult.Success)
-                                       return res;
-                       }
-
-                       if (prop.Set != null) {
-                               if ((res = AddProperty (prop, "set_" + prop.Name)) != AdditionResult.Success)
-                               return res;
-                       }
+                       if (!AddToMemberContainer (prop, false) || 
+                           !AddToMemberContainer (prop.Get, true) || !AddToMemberContainer (prop.Set, true))
+                               return;
 
                        if (properties == null)
                                properties = new MemberCoreArrayList ();
@@ -725,66 +621,50 @@ namespace Mono.CSharp {
                                properties.Insert (0, prop);
                        else
                                properties.Add (prop);
-
-                       return AdditionResult.Success;
                }
 
-               AdditionResult AddProperty (Property prop, string basename)
+               public void AddEvent (Event e)
                {
-                       AdditionResult res;
-                       string fullname = Name + "." + basename;
-
-                       if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
-                               return res;
-
-                       DefineName (fullname, prop);
-
-                       return AdditionResult.Success;
-               }
+                       if (!AddToMemberContainer (e, false))
+                               return;
 
-               public AdditionResult AddEvent (Event e)
-               {
-                       AdditionResult res;
-                       string basename = e.Name;
-                       string fullname = Name + "." + basename;
+                       if (e is EventProperty) {
+                               if (!AddToMemberContainer (e.Add, true))
+                                       return;
 
-                       if ((res = IsValid (basename, fullname)) != AdditionResult.Success)
-                               return res;
+                               if (!AddToMemberContainer (e.Remove, true))
+                                       return;
+                       }
 
                        if (events == null)
                                events = new MemberCoreArrayList ();
-                       
-                       events.Add (e);
-                       DefineName (fullname, e);
 
-                       return AdditionResult.Success;
+                       events.Add (e);
                }
 
+               /// <summary>
+               /// Indexer has special handling in constrast to other AddXXX because the name can be driven by IndexerNameAttribute
+               /// </summary>
                public void AddIndexer (Indexer i)
                {
                        if (indexers == null)
                                indexers = new IndexerArrayList (this);
 
-                       if (i.MemberName.Left != null)
+                       if (i.IsExplicitImpl)
                                indexers.Insert (0, i);
                        else
                                indexers.Add (i);
                }
 
-               public AdditionResult AddOperator (Operator op)
+               public void AddOperator (Operator op)
                {
+                       if (!AddToMemberContainer (op, true))
+                               return;
+
                        if (operators == null)
                                operators = new OperatorArrayList (this);
 
                        operators.Add (op);
-
-                       string basename = op.Name;
-                       string fullname = Name + "." + basename;
-                       if (!defined_names.Contains (fullname))
-                       {
-                               DefineName (fullname, op);
-                       }
-                       return AdditionResult.Success;
                }
 
                public void AddIterator (Iterator i)
@@ -984,7 +864,7 @@ namespace Mono.CSharp {
                //
                // Defines the default constructors
                //
-               void DefineDefaultConstructor (bool is_static)
+               protected void DefineDefaultConstructor (bool is_static)
                {
                        Constructor c;
 
@@ -1010,18 +890,6 @@ namespace Mono.CSharp {
                        
                }
 
-               public void ReportStructInitializedInstanceError ()
-               {
-                       string n = TypeBuilder.FullName;
-                       
-                       foreach (Field f in initialized_fields){
-                               Report.Error (
-                                       573, Location,
-                                       "`" + n + "." + f.Name + "': can not have " +
-                                       "instance field initializers in structs");
-                       }
-               }
-
                /// <remarks>
                ///  The pending methods that need to be implemented
                //   (interfaces or abstract methods)
@@ -1184,15 +1052,13 @@ namespace Mono.CSharp {
                                }
 
                                if (parent.IsSealed){
-                                       string detail = "";
-                                       
-                                       if (parent.IsValueType)
-                                               detail = " (a class can not inherit from a struct/enum)";
-                                       
-                                       Report.Error (509, "class `"+ Name +
-                                                     "': Cannot inherit from sealed class `"+
-                                                     parent.Name + "'" + detail);
                                        error = true;
+                                       Report.SymbolRelatedToPreviousError (parent.Type);
+                                       if (parent.Type.IsAbstract) {
+                                               Report.Error (709, Location, "'{0}': Cannot derive from static class", GetSignatureForError ());
+                                       } else {
+                                               Report.Error (509, Location, "'{0}': Cannot derive from sealed class", GetSignatureForError ());
+                                       }
                                        return null;
                                }
 
@@ -1303,42 +1169,46 @@ namespace Mono.CSharp {
                {
                        TypeExpr parent;
 
-                       if (TypeBuilder != null)
-                               return TypeBuilder;
-
                        if (error)
                                return null;
-                       
-                       if (InTransit) {
-                               Report.Error (146, Location, "Class definition is circular: `{0}'", Name);
-                               error = true;
-                               return null;
-                       }
-                       
-                       InTransit = true;
+
+                       if (TypeBuilder != null)
+                               return TypeBuilder;
 
                        ec = new EmitContext (this, Mono.CSharp.Location.Null, null, null, ModFlags);
 
                        TypeAttributes type_attributes = TypeAttr;
 
-                       if (IsTopLevel){
-                               if (TypeManager.NamespaceClash (Name, Location)) {
-                                       error = true;
-                                       return null;
-                               }
+                       try {
+                               if (IsTopLevel){
+                                       if (TypeManager.NamespaceClash (Name, Location)) {
+                                               error = true;
+                                               return null;
+                                       }
 
-                               ModuleBuilder builder = CodeGen.Module.Builder;
-                               TypeBuilder = builder.DefineType (
-                                       Name, type_attributes, null, null);
-                       } else {
-                               TypeBuilder builder = Parent.DefineType ();
-                               if (builder == null) {
-                                       error = true;
-                                       return null;
-                               }
+                                       ModuleBuilder builder = CodeGen.Module.Builder;
+                                       TypeBuilder = builder.DefineType (
+                                               Name, type_attributes, null, null);
+                               } else {
+                                       TypeBuilder builder;
+                                       if (Parent.TypeBuilder != null)
+                                               builder = Parent.TypeBuilder;
+                                       else
+                                               builder = Parent.DefineType ();
+
+                                       if (builder == null) {
+                                               error = true;
+                                               return null;
+                                       }
                                
-                               TypeBuilder = builder.DefineNestedType (
-                                       MemberName.Basename, type_attributes, null, null);
+                                       TypeBuilder = builder.DefineNestedType (
+                                               MemberName.Basename, type_attributes,
+                                               null, null);
+                               }
+                       }
+                       catch (ArgumentException) {
+                               Report.RuntimeMissingSupport ("static classes");
+                               return null;
                        }
 
                        TypeManager.AddUserType (Name, TypeBuilder, this);
@@ -1400,7 +1270,6 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       Type ptype;
                        ConstructedType constructed = parent_type as ConstructedType;
                        if ((constructed == null) && (parent_type != null))
                                ptype = parent_type.ResolveType (ec);
@@ -1415,6 +1284,11 @@ namespace Mono.CSharp {
                                }
                        }
 
+                       if (!CheckRecursiveDefinition ()) {
+                               error = true;
+                               return null;
+                       }
+
                        if (ptype != null)
                                TypeBuilder.SetParent (ptype);
 
@@ -1472,9 +1346,8 @@ namespace Mono.CSharp {
                                return null;
                        }
 
-                       InTransit = false;
                        return TypeBuilder;
-                                       }
+               }
 
                protected virtual bool DefineNestedTypes ()
                {
@@ -1512,6 +1385,32 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               protected bool CheckRecursiveDefinition ()
+               {
+                       if (InTransit) {
+                               Report.Error (146, Location,
+                                             "Class definition is circular: `{0}'",
+                                             GetSignatureForError ());
+                               error = true;
+                               return false;
+                       }
+
+                       InTransit = true;
+
+                       Type parent = ptype;
+                       if (parent != null) {
+                               if (parent.IsGenericInstance)
+                                       parent = parent.GetGenericTypeDefinition ();
+
+                               TypeContainer ptc = TypeManager.LookupTypeContainer (parent);
+                               if ((ptc != null) && !ptc.CheckRecursiveDefinition ())
+                                       return false;
+                       }
+
+                       InTransit = false;
+                       return true;
+               }
+
                static void Error_KeywordNotAllowed (Location loc)
                {
                        Report.Error (1530, loc, "Keyword new not allowed for namespace elements");
@@ -1557,7 +1456,7 @@ namespace Mono.CSharp {
                                if (Parent.MemberCache != null) {
                                        MemberInfo conflict_symbol = Parent.MemberCache.FindMemberWithSameName (Basename, false, TypeBuilder);
                                        if (conflict_symbol == null) {
-                                               if ((ModFlags & Modifiers.NEW) != 0)
+                                               if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0))
                                                        Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError ());
                                        } else {
                                                if ((ModFlags & Modifiers.NEW) == 0) {
@@ -1568,14 +1467,12 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (constants != null)
-                               constants.DefineContainerMembers ();
-
-                       if (fields != null)
-                               fields.DefineContainerMembers ();
+                       DefineContainerMembers (constants);
+                       DefineContainerMembers (fields);
 
-                       if ((Kind == Kind.Class) && !(this is ClassPart)){
-                               if (instance_constructors == null){
+                       if ((Kind == Kind.Class) && !(this is ClassPart) && !(this is StaticClass)){
+                               if ((instance_constructors == null) &&
+                                   !(this is StaticClass)) {
                                        if (default_constructor == null)
                                                DefineDefaultConstructor (false);
                                }
@@ -1610,32 +1507,18 @@ namespace Mono.CSharp {
                        //
                        // Constructors are not in the defined_names array
                        //
-                       if (instance_constructors != null)
-                               instance_constructors.DefineContainerMembers ();
-               
+                       DefineContainerMembers (instance_constructors);
+
                        if (default_static_constructor != null)
                                default_static_constructor.Define ();
 
-                       if (methods != null)
-                               methods.DefineContainerMembers ();
-
-                       if (properties != null)
-                               properties.DefineContainerMembers ();
-
-                       if (events != null)
-                               events.DefineContainerMembers ();
-
-                       if (indexers != null)
-                               indexers.DefineContainerMembers ();
-
-                       if (operators != null)
-                               operators.DefineContainerMembers ();
-
-                       if (enums != null)
-                               enums.DefineContainerMembers ();
-                       
-                       if (delegates != null)
-                               delegates.DefineContainerMembers ();
+                       DefineContainerMembers (properties);
+                       DefineContainerMembers (events);
+                       DefineContainerMembers (indexers);
+                       DefineContainerMembers (methods);
+                       DefineContainerMembers (operators);
+                       DefineContainerMembers (enums);
+                       DefineContainerMembers (delegates);
 
                        if (CurrentType != null) {
                                GenericType = CurrentType.ResolveType (ec);
@@ -1669,6 +1552,24 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               void ReportStructInitializedInstanceError ()
+               {
+                       string n = TypeBuilder.FullName;
+                       
+                       foreach (Field f in initialized_fields){
+                               Report.Error (
+                                       573, Location,
+                                       "`" + n + "." + f.Name + "': can not have " +
+                                       "instance field initializers in structs");
+                       }
+               }
+
+               protected virtual void DefineContainerMembers (MemberCoreArrayList mcal)
+               {
+                       if (mcal != null)
+                               mcal.DefineContainerMembers ();
+               }
+
                public override bool Define ()
                {
                        if (parts != null) {
@@ -2226,7 +2127,7 @@ namespace Mono.CSharp {
                                        }
                                }
 
-                               if (events != null){
+                               if ((events != null) && (RootContext.WarningLevel >= 3)) {
                                        foreach (Event e in events){
                                                if (e.status == 0)
                                                        Report.Warning (67, e.Location, "The event '{0}' is never used", e.GetSignatureForError ());
@@ -2481,13 +2382,10 @@ namespace Mono.CSharp {
                        return ok;
                }
 
-               Hashtable builder_and_args;
-               
-               public bool RegisterMethod (MethodBuilder mb, InternalParameters ip, Type [] args)
-               {
-                       if (builder_and_args == null)
-                               builder_and_args = new Hashtable ();
-                       return true;
+               public bool UserDefinedStaticConstructor {
+                       get {
+                               return default_static_constructor != null;
+                       }
                }
 
                protected override bool VerifyClsCompliance (DeclSpace ds)
@@ -2744,10 +2642,8 @@ namespace Mono.CSharp {
                {
                        if (Kind == Kind.Interface)
                                Parent.AddInterface (this);
-                       else if (Kind == Kind.Class)
-                               Parent.AddClass (this);
-                       else if (Kind == Kind.Struct)
-                               Parent.AddStruct (this);
+                       else if (Kind == Kind.Class || Kind == Kind.Struct)
+                               Parent.AddClassOrStruct (this);
                        else
                                throw new InvalidOperationException ();
                }
@@ -2867,6 +2763,87 @@ namespace Mono.CSharp {
 
                        base.ApplyAttributeBuilder (a, cb);
                }
+
+               public override void Register ()
+               {
+                       Parent.AddClassOrStruct (this);
+               }
+       }
+
+       /// <summary>
+       /// Class handles static classes declaration
+       /// </summary>
+       public sealed class StaticClass: Class {
+               public StaticClass (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
+                                   Attributes attrs, Location l)
+                       : base (ns, parent, name, mod & ~Modifiers.STATIC, attrs, l)
+               {
+                       if (RootContext.Version == LanguageVersion.ISO_1) {
+                               Report.FeatureIsNotStandardized (l, "static classes");
+                               Environment.Exit (1);
+                       }
+               }
+
+               protected override void DefineContainerMembers (MemberCoreArrayList list)
+               {
+                       if (list == null)
+                               return;
+
+                       foreach (MemberCore m in list) {
+                               if (m is Operator) {
+                                       Report.Error (715, m.Location, "'{0}': static classes cannot contain user-defined operators", m.GetSignatureForError (this));
+                                       continue;
+                               }
+
+                               if ((m.ModFlags & Modifiers.STATIC) != 0)
+                                       continue;
+
+                               if (m is Constructor) {
+                                       Report.Error (710, m.Location, "'{0}': Static classes cannot have instance constructors", GetSignatureForError ());
+                                       continue;
+                               }
+
+                               if (m is Destructor) {
+                                       Report.Error (711, m.Location, "'{0}': Static class cannot contain destructor", GetSignatureForError ());
+                                       continue;
+                               }
+                               Report.Error (708, m.Location, "'{0}': cannot declare instance members in a static class", m.GetSignatureForError (this));
+                       }
+
+                       base.DefineContainerMembers (list);
+               }
+
+               public override TypeBuilder DefineType()
+               {
+                       TypeBuilder tb = base.DefineType ();
+                       if (tb == null)
+                               return null;
+
+                       if ((ptype != null) && (ptype != TypeManager.object_type)) {
+                               Report.Error (
+                                       713, Location,
+                                       "Static class '{0}' cannot derive from type '{1}'. " +
+                                       "Static classes must derive from object",
+                                       GetSignatureForError (), ptype);
+                               return null;
+                       }
+
+                       if (ifaces != null) {
+                               foreach (Type t in ifaces)
+                                       Report.SymbolRelatedToPreviousError (t);
+                               Report.Error (
+                                       714, Location,
+                                       "'{0}': static classes cannot implement interfaces",
+                                       GetSignatureForError ());
+                       }
+                       return tb;
+               }
+
+               public override TypeAttributes TypeAttr {
+                       get {
+                               return base.TypeAttr | TypeAttributes.Abstract | TypeAttributes.Sealed;
+                       }
+               }
        }
 
        public class Class : ClassOrStruct {
@@ -2886,8 +2863,8 @@ namespace Mono.CSharp {
                // Information in the case we are an attribute type
                AttributeUsageAttribute attribute_usage;
 
-               public Class (NamespaceEntry ns, TypeContainer parent, MemberName name,
-                             int mod, Attributes attrs, Location l)
+               public Class (NamespaceEntry ns, TypeContainer parent, MemberName name, int mod,
+                             Attributes attrs, Location l)
                        : base (ns, parent, name, attrs, Kind.Class, l)
                {
                        int accmods;
@@ -2913,8 +2890,14 @@ namespace Mono.CSharp {
 
                public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
                {
-                       if (a.UsageAttribute != null)
+                       if (a.UsageAttribute != null) {
+                               if (ptype != TypeManager.attribute_type &&
+                                   !ptype.IsSubclassOf (TypeManager.attribute_type) &&
+                                   TypeBuilder.FullName != "System.Attribute") {
+                                       Report.Error (641, a.Location, "Attribute '{0}' is only valid on classes derived from System.Attribute", a.Name);
+                               }
                                attribute_usage = a.UsageAttribute;
+                       }
 
                        base.ApplyAttributeBuilder (a, cb);
                }
@@ -2925,11 +2908,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override void Register ()
-               {
-                       CheckDef (Parent.AddClass (this), Name, Location);
-               }
-
                public const TypeAttributes DefaultTypeAttributes =
                        TypeAttributes.AutoLayout | TypeAttributes.Class;
 
@@ -2978,11 +2956,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override void Register ()
-               {
-                       CheckDef (Parent.AddStruct (this), Name, Location);
-               }
-
                public const TypeAttributes DefaultTypeAttributes =
                        TypeAttributes.SequentialLayout |
                        TypeAttributes.Sealed |
@@ -3031,7 +3004,7 @@ namespace Mono.CSharp {
 
                public override void Register ()
                {
-                       CheckDef (Parent.AddInterface (this), Name, Location);
+                       Parent.AddInterface (this);
                }
 
                public override PendingImplementation GetPendingImplementations ()
@@ -3131,18 +3104,15 @@ namespace Mono.CSharp {
                        if (!DoDefineParameters ())
                                return false;
 
+                       if ((caching_flags & Flags.TestMethodDuplication) != 0 && !CheckForDuplications ())
+                               return false;
+
                        if (IsExplicitImpl)
                                return true;
 
-                       // TODO: Is it correct ?
-                       if (!IsOperator) {
-                               if (!CheckForDuplications ())
-                                       return false;
-                       }
-
                        // Is null for System.Object while compiling corlib and base interfaces
                        if (Parent.ParentContainer == null) {
-                               if ((ModFlags & Modifiers.NEW) != 0) {
+                               if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
                                        Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError (Parent));
                                }
                                return true;
@@ -3175,8 +3145,11 @@ namespace Mono.CSharp {
 
                                ObsoleteAttribute oa = AttributeTester.GetMethodObsoleteAttribute (parent_method);
                                if (oa != null) {
-                                       Report.SymbolRelatedToPreviousError (parent_method);
-                                       Report.Warning (672, Location, "Member '{0}' overrides obsolete member. Add the Obsolete attribute to '{0}'", GetSignatureForError (Parent));
+                                       EmitContext ec = new EmitContext (this.Parent, this.Parent, Location, null, null, ModFlags, false);
+                                       if (OptAttributes == null || !OptAttributes.Contains (TypeManager.obsolete_attribute_type, ec)) {
+                                               Report.SymbolRelatedToPreviousError (parent_method);
+                                               Report.Warning (672, 1, Location, "Member '{0}' overrides obsolete member. Add the Obsolete attribute to '{0}'", GetSignatureForError (Parent));
+                                       }
                                }
                                return true;
                        }
@@ -3188,7 +3161,7 @@ namespace Mono.CSharp {
 
                        MemberInfo conflict_symbol = Parent.FindMemberWithSameName (Name, !(this is Property));
                        if (conflict_symbol == null) {
-                               if ((ModFlags & Modifiers.NEW) != 0) {
+                               if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
                                        Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError (Parent));
                                }
                                return true;
@@ -3310,7 +3283,11 @@ namespace Mono.CSharp {
                        if ((ModFlags & (Modifiers.NEW | Modifiers.OVERRIDE)) == 0 && Name != "Finalize") {
                                ModFlags |= Modifiers.NEW;
                                Report.SymbolRelatedToPreviousError (parent_method);
-                               Report.Warning (!IsInterface && (parent_method.IsVirtual || parent_method.IsAbstract) ? 114 : 108, Location, GetSignatureForError (Parent));
+                               if (!IsInterface && (parent_method.IsVirtual || parent_method.IsAbstract)) {
+                                       if (RootContext.WarningLevel >= 2)
+                                               Report.Warning (114, Location, "'{0}' hides inherited member '{1}'. To make the current member override that implementation, add the override keyword. Otherwise add the new keyword", GetSignatureForError (Parent), parent_method);
+                               } else
+                                       Report.Warning (108, Location, "The keyword new is required on '{0}' because it hides inherited member", GetSignatureForError (Parent));
                        }
 
                        return ok;
@@ -3327,6 +3304,12 @@ namespace Mono.CSharp {
                                "member `" + name + "'");
                }
 
+               protected static string Error722 {
+                       get {
+                               return "'{0}': static types cannot be used as return types";
+                       }
+               }
+
                /// <summary>
                /// For custom member duplication search in a container
                /// </summary>
@@ -3345,7 +3328,8 @@ namespace Mono.CSharp {
                            !CheckParameters (ds, parameter_types))
                                return false;
 
-                       parameter_info = new InternalParameters (ds, Parameters);
+                       TypeParameter[] tparam = ds.IsGeneric ? ds.TypeParameters : null;
+                       parameter_info = new InternalParameters (ds, Parameters, tparam);
 
                        Parameter array_param = Parameters.ArrayParameter;
                        if ((array_param != null) &&
@@ -3451,7 +3435,8 @@ namespace Mono.CSharp {
 
                protected bool IsDuplicateImplementation (MethodCore method)
                {
-                       if ((method == this) || (method.Name != Name))
+                       if ((method == this) ||
+                           (method.MemberName.GetTypeName () != MemberName.GetTypeName ()))
                                return false;
 
                        Type[] param_types = method.ParameterTypes;
@@ -3495,10 +3480,13 @@ namespace Mono.CSharp {
                        }
 
                        for (int i = 0; i < param_types.Length; i++) {
-                               Type a = param_types [i];
-                               Type b = ParameterTypes [i];
-
-                               if (a != b)
+                               if (param_types [i] != ParameterTypes [i])
+                                       equal = false;
+                       }
+
+                       // TODO: make operator compatible with MethodCore to avoid this
+                       if (this is Operator && method is Operator) {
+                               if (MemberType != method.MemberType)
                                        equal = false;
                        }
 
@@ -3654,18 +3642,11 @@ namespace Mono.CSharp {
                        }
                }
                
-               //
-               // Returns the `System.Type' for the ReturnType of this
-               // function.  Provides a nice cache.  (used between semantic analysis
-               // and actual code generation
-               //
-               public Type GetReturnType ()
-               {
-                       return MemberType;
-               }
-
                public override string GetSignatureForError()
                {
+                       if (MethodBuilder == null) {
+                               return GetSignatureForError (Parent);
+                       }
                        return TypeManager.CSharpSignature (MethodBuilder);
                }
 
@@ -3674,6 +3655,10 @@ namespace Mono.CSharp {
                /// </summary>
                public override string GetSignatureForError (TypeContainer tc)
                {
+                       // TODO: get params from somewhere
+                       if (parameter_info == null)
+                               return base.GetSignatureForError (tc);
+
                        // TODO: move to parameters
                        System.Text.StringBuilder args = new System.Text.StringBuilder ();
                        if (parameter_info.Parameters.FixedParameters != null) {
@@ -3768,6 +3753,13 @@ namespace Mono.CSharp {
                                        Report.Error (629, Location, "Conditional member '{0}' cannot implement interface member", GetSignatureForError ());
                                        return;
                                }
+
+                               for (int i = 0; i < parameter_info.Count; ++i) {
+                                       if ((parameter_info.ParameterModifier (i) & Parameter.Modifier.OUT) != 0) {
+                                               Report.Error (685, Location, "Conditional method '{0}' cannot have an out parameter", GetSignatureForError ());
+                                               return;
+                                       }
+                               }
                        }
 
                        MethodBuilder.SetCustomAttribute (cb);
@@ -3776,12 +3768,39 @@ namespace Mono.CSharp {
                protected override bool CheckForDuplications ()
                {
                        ArrayList ar = Parent.Methods;
+                       if (ar != null) {
+                               int arLen = ar.Count;
+                                       
+                               for (int i = 0; i < arLen; i++) {
+                                       Method m = (Method) ar [i];
+                                       if (IsDuplicateImplementation (m))
+                                               return false;
+                               }
+                       }
+
+                       ar = Parent.Properties;
                        if (ar != null) {
-                               int arLen = ar.Count;
+                               for (int i = 0; i < ar.Count; ++i) {
+                                       PropertyBase pb = (PropertyBase) ar [i];
+                                       if (pb.AreAccessorsDuplicateImplementation (this))
+                                               return false;
+                               }
+                       }
 
-                               for (int i = 0; i < arLen; i++) {
-                                       Method m = (Method) ar [i];
-                                       if (IsDuplicateImplementation (m))
+                       ar = Parent.Indexers;
+                       if (ar != null) {
+                               for (int i = 0; i < ar.Count; ++i) {
+                                       PropertyBase pb = (PropertyBase) ar [i];
+                                       if (pb.AreAccessorsDuplicateImplementation (this))
+                                               return false;
+                               }
+                       }
+
+                       ar = Parent.Events;
+                       if (ar != null) {
+                               for (int i = 0; i < ar.Count; ++i) {
+                                       Event ev = (Event) ar [i];
+                                       if (ev.AreAccessorsDuplicateImplementation (this))
                                                return false;
                                }
                        }
@@ -3811,6 +3830,9 @@ namespace Mono.CSharp {
                        if (!CheckBase ())
                                return false;
 
+                       if (IsOperator)
+                               flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
+
                        MethodData = new MethodData (this, ParameterInfo, ModFlags, flags,
                                                     this, mb, GenericMethod);
 
@@ -3853,10 +3875,15 @@ namespace Mono.CSharp {
                                                 DuplicateEntryPoint (RootContext.EntryPoint, RootContext.EntryPointLocation);
                                                 DuplicateEntryPoint (MethodBuilder, Location);
                                         }
-                                } else                                         
-                                       {
-                                                                       Report.Warning (28, Location, "'{0}' has the wrong signature to be an entry point", TypeManager.CSharpSignature(MethodBuilder) );
-                                                               }
+                                } else {
+                                       if (RootContext.WarningLevel >= 4)
+                                               Report.Warning (28, Location, "'{0}' has the wrong signature to be an entry point", TypeManager.CSharpSignature(MethodBuilder) );
+                               }
+                       }
+
+                       if (MemberType.IsAbstract && MemberType.IsSealed) {
+                               Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
+                               return false;
                        }
 
                        return true;
@@ -3929,9 +3956,9 @@ namespace Mono.CSharp {
                        }
                }
 
-               public string MethodName {
+               public MemberName MethodName {
                        get {
-                               return ShortName;
+                               return MemberName;
                        }
                }
 
@@ -4002,6 +4029,7 @@ namespace Mono.CSharp {
                                return GenericMethod;
                        }
                }
+
                #endregion
        }
 
@@ -4086,7 +4114,7 @@ namespace Mono.CSharp {
                        }
                        
                        if (parent_constructor == caller_builder){
-                               Report.Error (515, String.Format ("Constructor `{0}' can not call itself", TypeManager.CSharpSignature (caller_builder)));
+                               Report.Error (516, String.Format ("Constructor `{0}' can not call itself", TypeManager.CSharpSignature (caller_builder)));
                                return false;
                        }
                        
@@ -4228,6 +4256,9 @@ namespace Mono.CSharp {
 
                public override string GetSignatureForError()
                {
+                       if (ConstructorBuilder == null)
+                               return GetSignatureForError (Parent);
+
                        return TypeManager.CSharpSignature (ConstructorBuilder);
                }
 
@@ -4307,7 +4338,7 @@ namespace Mono.CSharp {
                                }
                        }
                        
-                       if ((Parent.ModFlags & Modifiers.SEALED) != 0 && (ModFlags & Modifiers.PROTECTED) != 0) {
+                       if ((RootContext.WarningLevel >= 4) && ((Parent.ModFlags & Modifiers.SEALED) != 0 && (ModFlags & Modifiers.PROTECTED) != 0)) {
                                Report.Warning (628, Location, "'{0}': new protected member declared in sealed class", GetSignatureForError (Parent));
                        }
                        
@@ -4502,17 +4533,17 @@ namespace Mono.CSharp {
                        }
                }
 
-               public string MethodName {
+               public MemberName MethodName {
                        get {
-                               return ShortName;
-                       }
+                               return MemberName;
                        }
+               }
                        
                public Type ReturnType {
                        get {
                                return MemberType;
-                                       }
-                               }
+                       }
+               }
 
                public EmitContext CreateEmitContext (TypeContainer tc, ILGenerator ig)
                {
@@ -4546,7 +4577,7 @@ namespace Mono.CSharp {
        {
                CallingConventions CallingConventions { get; }
                Location Location { get; }
-               string MethodName { get; }
+               MemberName MethodName { get; }
                Type[] ParameterTypes { get; }
                Type ReturnType { get; }
                GenericMethod GenericMethod { get; }
@@ -4649,15 +4680,16 @@ namespace Mono.CSharp {
                public bool Define (TypeContainer container)
                {
                        MethodInfo implementing = null;
-                       string prefix;
 
+                       string prefix;
                        if (member.IsExplicitImpl)
                                prefix = RemoveArity (member.InterfaceType.FullName) + ".";
                        else
                                prefix = "";
 
-                       string name = method.MethodName;
+                       string name = method.MethodName.Name;
                        string method_name = prefix + name;
+  
                        Type[] ParameterTypes = method.ParameterTypes;
 
                        if (container.Pending != null){
@@ -4738,12 +4770,6 @@ namespace Mono.CSharp {
                                if ((modifiers & (Modifiers.VIRTUAL | Modifiers.ABSTRACT | Modifiers.OVERRIDE)) == 0)
                                        flags |= MethodAttributes.Final;
 
-                               // Get the method name from the explicit interface.
-                               if (member.InterfaceType != null) {
-                                       name = implementing.Name;
-                                       method_name = prefix + name;
-                               }
-
                                IsImplementing = true;
                        }
 
@@ -4754,11 +4780,6 @@ namespace Mono.CSharp {
                        if (builder == null)
                                return false;
 
-                       if (GenericMethod != null) {
-                               if (!GenericMethod.DefineType (ec, builder))
-                                       return false;
-                       }
-
                        if (container.CurrentType != null)
                                declaring_type = container.CurrentType.ResolveType (ec);
                        else
@@ -4774,7 +4795,7 @@ namespace Mono.CSharp {
                                if (member is Indexer) {
                                        container.Pending.ImplementIndexer (
                                                member.InterfaceType, builder, method.ReturnType,
-                                               ParameterTypes, true);
+                                               ParameterTypes, member.IsExplicitImpl);
                                } else
                                        container.Pending.ImplementMethod (
                                                member.InterfaceType, name, method.ReturnType,
@@ -4786,17 +4807,20 @@ namespace Mono.CSharp {
 
                        }
 
-                       if (!TypeManager.RegisterMethod (builder, ParameterInfo, ParameterTypes)) {
-                               Report.Error (111, method.Location,
-                                             "Class `" + container.Name +
-                                             "' already contains a definition with the " +
-                                             "same return value and parameter types as the " +
-                                             "'get' method of property `" + member.Name + "'");
-                               return false;
-                       }
-
+                       TypeManager.RegisterMethod (builder, ParameterInfo, ParameterTypes);
                        TypeManager.AddMethod (builder, method);
 
+                       if (GenericMethod != null) {
+                               bool is_override = member.IsExplicitImpl |
+                                       ((modifiers & Modifiers.OVERRIDE) != 0);
+
+                               is_override &= IsImplementing;
+
+                               if (!GenericMethod.DefineType (
+                                           ec, builder, implementing, is_override))
+                                       return false;
+                       }
+
                        return true;
                }
 
@@ -4996,7 +5020,7 @@ namespace Mono.CSharp {
                //
                // The name of the interface we are explicitly implementing
                //
-               public Expression ExplicitInterfaceName = null;
+               public MemberName ExplicitInterfaceName = null;
 
                //
                // Whether this is an interface member.
@@ -5019,6 +5043,14 @@ namespace Mono.CSharp {
                        explicit_mod_flags = mod;
                        Type = type;
                        ModFlags = Modifiers.Check (allowed_mod, mod, def_mod, loc);
+
+                       // Check for explicit interface implementation
+                       if (MemberName.Left != null) {
+                               ExplicitInterfaceName = MemberName.Left;
+                               ShortName = MemberName.Name;
+                               IsExplicitImpl = true;
+                       } else
+                               ShortName = Name;
                }
 
                protected virtual bool CheckBase ()
@@ -5028,9 +5060,11 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if ((Parent.ModFlags & Modifiers.SEALED) != 0 && (ModFlags & Modifiers.PROTECTED) != 0 &&
-                           (ModFlags & Modifiers.OVERRIDE) == 0 && Name != "Finalize") {
-                               Report.Warning (628, Location, "'{0}': new protected member declared in sealed class", GetSignatureForError (Parent));
+                       if ((RootContext.WarningLevel >= 4) &&
+                           ((Parent.ModFlags & Modifiers.SEALED) != 0) &&
+                           ((ModFlags & Modifiers.PROTECTED) != 0) &&
+                           ((ModFlags & Modifiers.OVERRIDE) == 0) && (Name != "Finalize")) {
+                               Report.Warning (628, Location, "'{0}': new protected member declared in sealed class", GetSignatureForError (Parent));
                        }
 
                        return true;
@@ -5084,7 +5118,7 @@ namespace Mono.CSharp {
                protected virtual bool DoDefineBase ()
                {
                        if (Name == null)
-                               Name = "this";
+                               throw new InternalErrorException ();
 
                        if (IsInterface) {
                                ModFlags = Modifiers.PUBLIC |
@@ -5154,18 +5188,9 @@ namespace Mono.CSharp {
                        if (MemberType.IsPointer && !UnsafeOK (Parent))
                                return false;
 
-                       //
-                       // Check for explicit interface implementation
-                       //
-                       if (MemberName.Left != null) {
-                               ExplicitInterfaceName = MemberName.Left.GetTypeExpression (Location);
-                               ShortName = MemberName.Name;
-                       } else
-                               ShortName = Name;
-
-                       if (ExplicitInterfaceName != null) {
+                       if (IsExplicitImpl) {
                                InterfaceType = Parent.ResolveType (
-                                       ExplicitInterfaceName, false, Location);
+                                       ExplicitInterfaceName.GetTypeExpression (Location), false, Location);
                                if (InterfaceType == null)
                                        return false;
 
@@ -5174,27 +5199,26 @@ namespace Mono.CSharp {
                                        return false;
                                }
 
-                               // Compute the full name that we need to export.
-                               Name = InterfaceType.FullName + "." + ShortName;
-                               
                                if (!Parent.VerifyImplements (InterfaceType, ShortName, Name, Location))
                                        return false;
                                
                                Modifiers.Check (Modifiers.AllowedExplicitImplFlags, explicit_mod_flags, 0, Location);
-                               
-                               IsExplicitImpl = true;
-                       } else
-                               IsExplicitImpl = false;
+                       }
 
                        return true;
                }
 
                /// <summary>
-               /// Use this method when MethodBuilder is null
+               /// The name of the member can be changed during definition (see IndexerName attribute)
                /// </summary>
-               public virtual string GetSignatureForError (TypeContainer tc)
+               protected virtual void UpdateMemberName ()
+               {
+                       MemberName.Name = ShortName;
+               }
+
+               public override string GetSignatureForError (TypeContainer tc)
                {
-                       return String.Concat (tc.Name, '.', Name);
+                       return String.Concat (tc.Name, '.', base.GetSignatureForError (tc));
                }
 
                protected override bool VerifyClsCompliance(DeclSpace ds)
@@ -5321,7 +5345,7 @@ namespace Mono.CSharp {
 
                        conflict_symbol = Parent.FindMemberWithSameName (Name, false);
                        if (conflict_symbol == null) {
-                               if ((ModFlags & Modifiers.NEW) != 0) {
+                               if ((RootContext.WarningLevel >= 4) && ((ModFlags & Modifiers.NEW) != 0)) {
                                        Report.Warning (109, Location, "The member '{0}' does not hide an inherited member. The new keyword is not required", GetSignatureForError (Parent));
                                }
                                return true;
@@ -5356,6 +5380,9 @@ namespace Mono.CSharp {
 
                public override string GetSignatureForError ()
                {
+                       if (FieldBuilder == null) {
+                               return base.GetSignatureForError (Parent);
+                       }
                        return TypeManager.GetFullNameSignature (FieldBuilder);
                }
 
@@ -5525,35 +5552,60 @@ namespace Mono.CSharp {
                //
                public Block Block;
                public Attributes Attributes;
+               public Location Location;
                
-               public Accessor (Block b, Attributes attrs)
+               public Accessor (Block b, Attributes attrs, Location loc)
                {
                        Block = b;
                        Attributes = attrs;
+                       Location = loc;
                }
        }
 
 
        // Ooouh Martin, templates are missing here.
        // When it will be possible move here a lot of child code and template method type.
-       public abstract class AbstractPropertyEventMethod: Attributable, IMethodData
-       {
+       public abstract class AbstractPropertyEventMethod: MemberCore, IMethodData {
                protected MethodData method_data;
                protected Block block;
 
+               // The accessor are created event if they are not wanted.
+               // But we need them because their names are reserved.
+               // Field says whether accessor will be emited or not
+               public readonly bool IsDummy;
+
+               protected readonly string prefix;
+
                ReturnParameter return_attributes;
 
-               public AbstractPropertyEventMethod ():
-                       base (null)
+               public AbstractPropertyEventMethod (MemberBase member, string prefix)
+                       : base (null, SetupName (prefix, member), null, member.Location)
                {
+                       this.prefix = prefix;
+                       IsDummy = true;
                }
 
-               public AbstractPropertyEventMethod (Accessor accessor):
-                       base (accessor.Attributes)
+               public AbstractPropertyEventMethod (MemberBase member, Accessor accessor,
+                                                   string prefix)
+                       : base (null, SetupName (prefix, member),
+                               accessor.Attributes, accessor.Location)
                {
+                       this.prefix = prefix;
                        this.block = accessor.Block;
                }
 
+               static MemberName SetupName (string prefix, MemberBase member)
+               {
+                       MemberName name = member.MemberName.Clone ();
+                       name.Name = prefix + member.ShortName;
+                       return name;
+               }
+
+               public void UpdateName (MemberBase member)
+               {
+                       MemberName.Name = prefix + member.ShortName;
+               }
+
                #region IMethodData Members
 
                public Block Block {
@@ -5583,10 +5635,13 @@ namespace Mono.CSharp {
                        }
                }
 
+               public MemberName MethodName {
+                       get {
+                               return MemberName;
+                       }
+               }
+
                public abstract ObsoleteAttribute GetObsoleteAttribute ();
-               public abstract string GetSignatureForError (TypeContainer tc);
-               public abstract Location Location { get; }
-               public abstract string MethodName { get; }
                public abstract Type[] ParameterTypes { get; }
                public abstract Type ReturnType { get; }
                public abstract EmitContext CreateEmitContext(TypeContainer tc, ILGenerator ig);
@@ -5622,11 +5677,52 @@ namespace Mono.CSharp {
                        System.Diagnostics.Debug.Fail ("You forgot to define special attribute target handling");
                }
 
+               public override bool Define()
+               {
+                       return false;
+               }
+
                public virtual void Emit (TypeContainer container)
                {
                        method_data.Emit (container, this);
                        block = null;
                }
+
+               public override bool IsClsCompliaceRequired(DeclSpace ds)
+               {
+                       return false;
+               }
+
+               public bool IsDuplicateImplementation (MethodCore method)
+               {
+                       if (Name != method.Name)
+                               return false;
+
+                       Type[] param_types = method.ParameterTypes;
+
+                       if (param_types.Length != ParameterTypes.Length)
+                               return false;
+
+                       for (int i = 0; i < param_types.Length; i++)
+                               if (param_types [i] != ParameterTypes [i])
+                                       return false;
+
+                       Report.SymbolRelatedToPreviousError (method);
+                       Report.Error (111, Location, "Type '{0}' already defines a member called '{1}' with " +
+                                     "the same parameter types", Parent.Name, Name);
+                       return true;
+               }
+
+               public new Location Location { 
+                       get {
+                               return base.Location;
+                       }
+               }
+
+               protected override void VerifyObsoleteAttribute()
+               {
+               }
+
        }
 
        //
@@ -5639,8 +5735,13 @@ namespace Mono.CSharp {
                {
                        static string[] attribute_targets = new string [] { "method", "return" };
 
+                       public GetMethod (MethodCore method):
+                               base (method, "get_")
+                       {
+                       }
+
                        public GetMethod (MethodCore method, Accessor accessor):
-                               base (method, accessor)
+                               base (method, accessor, "get_")
                        {
                        }
 
@@ -5659,13 +5760,6 @@ namespace Mono.CSharp {
                                return String.Concat (base.GetSignatureForError (tc), ".get");
                        }
 
-                       public override string MethodName 
-                       {
-                               get {
-                                       return "get_" + method.ShortName;
-                               }
-                       }
-
                        public override Type ReturnType {
                                get {
                                        return method.MemberType;
@@ -5684,8 +5778,13 @@ namespace Mono.CSharp {
                        static string[] attribute_targets = new string [] { "method", "param", "return" };
                        ImplicitParameter param_attr;
 
+                       public SetMethod (MethodCore method):
+                               base (method, "set_")
+                       {
+                       }
+
                        public SetMethod (MethodCore method, Accessor accessor):
-                               base (method, accessor)
+                               base (method, accessor, "set_")
                        {
                        }
 
@@ -5725,12 +5824,6 @@ namespace Mono.CSharp {
                                return String.Concat (base.GetSignatureForError (tc), ".set");
                        }
 
-                       public override string MethodName {
-                               get {
-                                       return "set_" + method.ShortName;
-                               }
-                       }
-
                        public override Type[] ParameterTypes {
                                get {
                                        return new Type[] { method.MemberType };
@@ -5755,8 +5848,14 @@ namespace Mono.CSharp {
                public abstract class PropertyMethod: AbstractPropertyEventMethod {
                        protected readonly MethodCore method;
 
-                       public PropertyMethod (MethodCore method, Accessor accessor):
-                               base (accessor)
+                       public PropertyMethod (MethodCore method, string prefix)
+                               : base (method, prefix)
+                       {
+                               this.method = method;
+                       }
+
+                       public PropertyMethod (MethodCore method, Accessor accessor, string prefix)
+                               : base (method, accessor, prefix)
                        {
                                this.method = method;
                        }
@@ -5787,12 +5886,6 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override Location Location {
-                               get {
-                                       return method.Location;
-                               }
-                       }
-
                        public override EmitContext CreateEmitContext (TypeContainer tc,
                                                                       ILGenerator ig)
                        {
@@ -5848,32 +5941,51 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       ec = new EmitContext (Parent, Location, null, MemberType, ModFlags);
+                       if (MemberType.IsAbstract && MemberType.IsSealed) {
+                               Report.Error (722, Location, Error722, TypeManager.CSharpName (MemberType));
+                               return false;
+                       }
 
+                       ec = new EmitContext (Parent, Location, null, MemberType, ModFlags);
                        return true;
                }
 
                public override string GetSignatureForError()
                {
+                       if (PropertyBuilder == null)
+                               return GetSignatureForError (Parent);
+
                        return TypeManager.CSharpSignature (PropertyBuilder, false);
                }
 
 
                protected override bool CheckForDuplications ()
                {
-                       ArrayList ar = Parent.Properties;
+                       ArrayList ar = Parent.Indexers;
                        if (ar != null) {
                                int arLen = ar.Count;
                                        
                                for (int i = 0; i < arLen; i++) {
-                                       Property m = (Property) ar [i];
+                                       Indexer m = (Indexer) ar [i];
                                        if (IsDuplicateImplementation (m))
                                                return false;
                                }
                        }
-                               return true;
+
+                       ar = Parent.Properties;
+                       if (ar != null) {
+                               int arLen = ar.Count;
+                                       
+                               for (int i = 0; i < arLen; i++) {
+                                       Property m = (Property) ar [i];
+                                       if (IsDuplicateImplementation (m))
+                                               return false;
+                               }
                        }
 
+                       return true;
+               }
+
                protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
                {
                        PropertyInfo parent_property = container.ParentContainer.MemberCache.FindMemberToOverride (
@@ -5903,15 +6015,32 @@ namespace Mono.CSharp {
                        if (PropertyBuilder != null && OptAttributes != null)
                                OptAttributes.Emit (ec, this);
 
-                       if (Get != null)
+                       if (!Get.IsDummy)
                                Get.Emit (Parent);
 
-                       if (Set != null)
+                       if (!Set.IsDummy)
                                Set.Emit (Parent);
 
                        base.Emit ();
                }
 
+               /// <summary>
+               /// Tests whether accessors are not in collision with some method (CS0111)
+               /// </summary>
+               public bool AreAccessorsDuplicateImplementation (MethodCore mc)
+               {
+                       return Get.IsDuplicateImplementation (mc) || Set.IsDuplicateImplementation (mc);
+               }
+
+               protected override void UpdateMemberName ()
+               {
+                       base.UpdateMemberName ();
+
+                       Get.UpdateName (this);
+                       Set.UpdateName (this);
+               }
+
+
                public override string[] ValidAttributeTargets {
                        get {
                                return attribute_targets;
@@ -5946,10 +6075,14 @@ namespace Mono.CSharp {
                                is_iface, name, Parameters.EmptyReadOnlyParameters, attrs,
                                loc)
                {
-                       if (get_block != null)
+                       if (get_block == null)
+                               Get = new GetMethod (this);
+                       else
                                Get = new GetMethod (this, get_block);
 
-                       if (set_block != null)
+                       if (set_block == null)
+                               Set = new SetMethod (this);
+                       else
                                Set = new SetMethod (this, set_block);
                }
 
@@ -5966,7 +6099,7 @@ namespace Mono.CSharp {
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
 
-                       if (Get != null) {
+                       if (!Get.IsDummy) {
 
                                GetBuilder = Get.Define (Parent);
                                if (GetBuilder == null)
@@ -5987,7 +6120,7 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       if (Set != null) {
+                       if (!Set.IsDummy) {
                                SetBuilder = Set.Define (Parent);
                                if (SetBuilder == null)
                                        return false;
@@ -6006,23 +6139,13 @@ namespace Mono.CSharp {
                                PropertyBuilder = Parent.TypeBuilder.DefineProperty (
                                        Name, prop_attr, MemberType, null);
                                
-                               if (Get != null)
+                               if (!Get.IsDummy)
                                        PropertyBuilder.SetGetMethod (GetBuilder);
                                
-                               if (Set != null)
+                               if (!Set.IsDummy)
                                        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;
-                               }
+                               TypeManager.RegisterProperty (PropertyBuilder, GetBuilder, SetBuilder);
                        }
                        return true;
                }
@@ -6244,22 +6367,17 @@ namespace Mono.CSharp {
 
                protected sealed class AddDelegateMethod: DelegateMethod
                {
+
                        public AddDelegateMethod (Event method):
-                               base (method)
+                               base (method, "add_")
                        {
                        }
 
                        public AddDelegateMethod (Event method, Accessor accessor):
-                               base (method, accessor)
+                               base (method, accessor, "add_")
                        {
                        }
 
-                       public override string MethodName {
-                               get {
-                                       return "add_" + method.ShortName;
-                               }
-                       }
-
                        protected override MethodInfo DelegateMethodInfo {
                                get {
                                        return TypeManager.delegate_combine_delegate_delegate;
@@ -6271,21 +6389,15 @@ namespace Mono.CSharp {
                protected sealed class RemoveDelegateMethod: DelegateMethod
                {
                        public RemoveDelegateMethod (Event method):
-                               base (method)
+                               base (method, "remove_")
                        {
                        }
 
                        public RemoveDelegateMethod (Event method, Accessor accessor):
-                               base (method, accessor)
+                               base (method, accessor, "remove_")
                        {
                        }
 
-                       public override string MethodName {
-                               get {
-                                       return "remove_" + method.ShortName;
-                               }
-                       }
-
                        protected override MethodInfo DelegateMethodInfo {
                                get {
                                        return TypeManager.delegate_remove_delegate_delegate;
@@ -6301,13 +6413,14 @@ namespace Mono.CSharp {
 
                        static string[] attribute_targets = new string [] { "method", "param", "return" };
 
-                       public DelegateMethod (Event method)
+                       public DelegateMethod (Event method, string prefix)
+                               : base (method, prefix)
                        {
                                this.method = method;
                        }
 
-                       public DelegateMethod (Event method, Accessor accessor):
-                               base (accessor)
+                       public DelegateMethod (Event method, Accessor accessor, string prefix)
+                               : base (method, accessor, prefix)
                        {
                                this.method = method;
                        }
@@ -6394,12 +6507,6 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       public override Location Location {
-                               get {
-                                       return method.Location;
-                               }
-                       }
-
                        public override EmitContext CreateEmitContext (TypeContainer tc,
                                                                       ILGenerator ig)
                        {
@@ -6442,7 +6549,7 @@ namespace Mono.CSharp {
                const int AllowedInterfaceModifiers =
                        Modifiers.NEW;
 
-               protected DelegateMethod Add, Remove;
+               public DelegateMethod Add, Remove;
                public MyEventBuilder     EventBuilder;
                public MethodBuilder AddBuilder, RemoveBuilder;
 
@@ -6463,6 +6570,11 @@ namespace Mono.CSharp {
                        EventBuilder.SetCustomAttribute (cb);
                }
 
+               public bool AreAccessorsDuplicateImplementation (MethodCore mc)
+               {
+                       return Add.IsDuplicateImplementation (mc) || Remove.IsDuplicateImplementation (mc);
+               }
+
                public override AttributeTargets AttributeTargets {
                        get {
                                return AttributeTargets.Event;
@@ -6529,13 +6641,7 @@ namespace Mono.CSharp {
                                EventBuilder.SetAddOnMethod (AddBuilder);
                                EventBuilder.SetRemoveOnMethod (RemoveBuilder);
 
-                               if (!TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder)) {
-                                       Report.Error (111, Location,
-                                                     "Class `" + Parent.Name +
-                                                     "' already contains a definition for the event `" +
-                                                     Name + "'");
-                                       return false;
-                               }
+                               TypeManager.RegisterEvent (EventBuilder, AddBuilder, RemoveBuilder);
                        }
                        
                        return true;
@@ -6575,24 +6681,23 @@ namespace Mono.CSharp {
 
                public override string GetSignatureForError ()
                {
+                       if (EventBuilder == null)
+                               return base.GetSignatureForError (Parent);
+
                        return TypeManager.GetFullNameSignature (EventBuilder);
                }
        }
 
-       //
-       // FIXME: This does not handle:
-       //
-       //   int INTERFACENAME [ args ]
-       //   Does not 
-       //
-       // Only:
-       // 
-       // int this [ args ]
  
        public class Indexer : PropertyBase {
 
                class GetIndexerMethod: GetMethod
                {
+                       public GetIndexerMethod (MethodCore method):
+                               base (method)
+                       {
+                       }
+
                        public GetIndexerMethod (MethodCore method, Accessor accessor):
                                base (method, accessor)
                        {
@@ -6609,6 +6714,11 @@ namespace Mono.CSharp {
                {
                        readonly Parameters parameters;
 
+                       public SetIndexerMethod (MethodCore method):
+                               base (method)
+                       {
+                       }
+
                        public SetIndexerMethod (MethodCore method, Parameters parameters, Accessor accessor):
                                base (method, accessor)
                        {
@@ -6675,24 +6785,24 @@ namespace Mono.CSharp {
                const int AllowedInterfaceModifiers =
                        Modifiers.NEW;
 
-               public string IndexerName = TypeContainer.DefaultIndexerName;
-               public string InterfaceIndexerName;
-
                //
                // Are we implementing an interface ?
                //
-               public Indexer (TypeContainer parent, Expression type, int mod_flags,
-                               bool is_iface, MemberName name, Parameters parameters,
-                               Attributes attrs, Accessor get_block, Accessor set_block,
-                               Location loc)
-                       : base (parent, type, mod_flags,
+               public Indexer (TypeContainer parent, Expression type, MemberName name, int mod,
+                               bool is_iface, Parameters parameters, Attributes attrs,
+                               Accessor get_block, Accessor set_block, Location loc)
+                       : base (parent, type, mod,
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                is_iface, name, parameters, attrs, loc)
                {
-                       if (get_block != null)
+                       if (get_block == null)
+                               Get = new GetIndexerMethod (this);
+                       else
                                Get = new GetIndexerMethod (this, get_block);
 
-                       if (set_block != null)
+                       if (set_block == null)
+                               Set = new SetIndexerMethod (this);
+                       else
                                Set = new SetIndexerMethod (this, parameters, set_block);
                }
 
@@ -6711,9 +6821,9 @@ namespace Mono.CSharp {
                        if (OptAttributes != null) {
                                Attribute indexer_attr = OptAttributes.GetIndexerNameAttribute (ec);
                                if (indexer_attr != null) {
-                                       IndexerName = indexer_attr.GetIndexerAttributeValue (ec);
+                                       ShortName = indexer_attr.GetIndexerAttributeValue (ec);
+
                                        if (IsExplicitImpl) {
-                                               // The 'IndexerName' attribute is valid only on an indexer that is not an explicit interface member declaration
                                                Report.Error (415, indexer_attr.Location, "The 'IndexerName' attribute is valid only on an indexer that is not an explicit interface member declaration");
                                                return false;
                                        }
@@ -6723,37 +6833,37 @@ namespace Mono.CSharp {
                                                return false;
                                        }
 
-                                       if (!Tokenizer.IsValidIdentifier (IndexerName)) {
-                                               // The argument to the 'IndexerName' attribute must be a valid identifier
+                                       if (!Tokenizer.IsValidIdentifier (ShortName)) {
                                                Report.Error (633, indexer_attr.Location, "The argument to the 'IndexerName' attribute must be a valid identifier");
                                                return false;
                                        }
+
+                                       UpdateMemberName ();
                                }
                        }
 
-                       ShortName = IndexerName;
-                       if (IsExplicitImpl) {
-                               InterfaceIndexerName = TypeManager.IndexerPropertyName (InterfaceType);
-                               Name = InterfaceType.FullName + "." + IndexerName;
-                       } else {
-                               InterfaceIndexerName = IndexerName;
-                               Name = ShortName;
+                       if (InterfaceType != null) {
+                               string parent_IndexerName = TypeManager.IndexerPropertyName (InterfaceType);
+                               if (parent_IndexerName != Name)
+                                       ShortName = parent_IndexerName;
+                               UpdateMemberName ();
                        }
 
-                       if (!CheckNameCollision (Parent))
+                       if (!Parent.AddToMemberContainer (this, true) ||
+                           !Parent.AddToMemberContainer (Get, true) || !Parent.AddToMemberContainer (Set, true))
                                return false;
 
                        if (!CheckBase ())
                                return false;
 
                        flags |= MethodAttributes.HideBySig | MethodAttributes.SpecialName;
-                       if (Get != null){
+                       if (!Get.IsDummy){
                                GetBuilder = Get.Define (Parent);
                                if (GetBuilder == null)
                                        return false;
                        }
                        
-                       if (Set != null){
+                       if (!Set.IsDummy){
                                SetBuilder = Set.Define (Parent);
                                if (SetBuilder == null)
                                        return false;
@@ -6764,19 +6874,24 @@ namespace Mono.CSharp {
                        //
                        Parameter [] p = Parameters.FixedParameters;
                        if (p != null) {
+                               if ((p [0].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
+                                       Report.Error (631, Location, "ref and out are not valid in this context");
+                                       return false;
+                               }
+
                                int i;
                                
                                for (i = 0; i < p.Length; ++i) {
-                                       if (Get != null)
+                                       if (!Get.IsDummy)
                                                GetBuilder.DefineParameter (
                                                        i + 1, p [i].Attributes, p [i].Name);
 
-                                       if (Set != null)
+                                       if (!Set.IsDummy)
                                                SetBuilder.DefineParameter (
                                                        i + 1, p [i].Attributes, p [i].Name);
                                }
 
-                               if (Set != null)
+                               if (!Set.IsDummy)
                                        SetBuilder.DefineParameter (
                                                i + 1, ParameterAttributes.None, "value");
                                        
@@ -6796,12 +6911,12 @@ namespace Mono.CSharp {
                        //
                        if (!IsExplicitImpl) {
                                PropertyBuilder = Parent.TypeBuilder.DefineProperty (
-                                       IndexerName, prop_attr, MemberType, ParameterTypes);
+                                       ShortName, prop_attr, MemberType, ParameterTypes);
 
-                               if (Get != null)
+                               if (!Get.IsDummy)
                                        PropertyBuilder.SetGetMethod (GetBuilder);
 
-                               if (Set != null)
+                               if (!Set.IsDummy)
                                        PropertyBuilder.SetSetMethod (SetBuilder);
                                
                                TypeManager.RegisterIndexer (PropertyBuilder, GetBuilder, SetBuilder,
@@ -6811,58 +6926,21 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               bool CheckNameCollision (TypeContainer container) {
-                       switch (VerifyName (container)){
-                               case DeclSpace.AdditionResult.NameExists:
-                                       Report.Error (102, Location, "The container '{0}' already contains a definition for '{1}'", container.GetSignatureForError (), Name);
-                                       return false;
-
-                               case DeclSpace.AdditionResult.Success:
-                                       return true;
-                       }
-                       throw new NotImplementedException ();
-               }
-
-               DeclSpace.AdditionResult VerifyName (TypeContainer container) {
-                       if (!AddIndexer (container, container.Name + "." + Name))
-                               return DeclSpace.AdditionResult.NameExists;
-
-                       if (Get != null) {
-                               if (!AddIndexer (container, container.Name + ".get_" + Name))
-                                       return DeclSpace.AdditionResult.NameExists;
-                       }
-
-                       if (Set != null) {
-                               if (!AddIndexer (container, container.Name + ".set_" + Name))
-                                       return DeclSpace.AdditionResult.NameExists;
-                       }
-                       return DeclSpace.AdditionResult.Success;
-               }
-
-               bool AddIndexer (TypeContainer container, string fullname)
-               {
-                       object value = container.GetDefinition (fullname);
-
-                       if (value != null) {
-                               return value.GetType () != GetType () ? false : true;
-                       }
-
-                       container.DefineName (fullname, this);
-                       return true;
-               }
-
                public override string GetSignatureForError ()
                {
+                       if (PropertyBuilder == null)
+                               return GetSignatureForError (Parent);
+
                        return TypeManager.CSharpSignature (PropertyBuilder, true);
                }
 
                public override string GetSignatureForError(TypeContainer tc)
                {
-                       return String.Concat (tc.Name, ".this[", TypeManager.CSharpName (ParameterTypes [0]), ']');
+                       return String.Concat (tc.Name, ".this[", Parameters.FixedParameters [0].TypeName.ToString (), ']');
                }
        }
 
-       public class Operator : MemberBase, IIteratorContainer {
+       public class Operator : MethodCore, IIteratorContainer {
 
                const int AllowedModifiers =
                        Modifiers.PUBLIC |
@@ -6913,40 +6991,22 @@ namespace Mono.CSharp {
                };
 
                public readonly OpType OperatorType;
-               public readonly Expression ReturnType;
-               public readonly Expression FirstArgType, SecondArgType;
-               public readonly string FirstArgName, SecondArgName;
-               public Block           Block;
                public MethodBuilder   OperatorMethodBuilder;
                
-               public string MethodName;
                public Method OperatorMethod;
 
                static string[] attribute_targets = new string [] { "method", "return" };
 
                public Operator (TypeContainer parent, OpType type, Expression ret_type,
-                                int mod_flags, Expression arg1type, string arg1name,
-                                Expression arg2type, string arg2name,
+                                int mod_flags, Parameters parameters,
                                 Block block, Attributes attrs, Location loc)
-                       : base (parent, ret_type, mod_flags, AllowedModifiers,
-                               Modifiers.PUBLIC, MemberName.Null, attrs, loc)
+                       : base (parent, null, ret_type, mod_flags, AllowedModifiers, false,
+                               new MemberName ("op_" + type), attrs, parameters, loc)
                {
                        OperatorType = type;
-                       Name = "op_" + OperatorType;
-                       ReturnType = ret_type;
-                       FirstArgType = arg1type;
-                       FirstArgName = arg1name;
-                       SecondArgType = arg2type;
-                       SecondArgName = arg2name;
                        Block = block;
                }
 
-               string Prototype (TypeContainer container)
-               {
-                       return container.Name + ".operator " + OperatorType + " (" + FirstArgType + "," +
-                               SecondArgType + ")";
-               }
-
                public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb) 
                {
                        OperatorMethod.ApplyAttributeBuilder (a, cb);
@@ -6963,51 +7023,68 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public override bool Define ()
+               protected override bool CheckForDuplications()
                {
-                       int length = 1;
-                       MethodName = "op_" + OperatorType;
-                       
-                       if (SecondArgType != null)
-                               length = 2;
-                       
-                       Parameter [] param_list = new Parameter [length];
+                       ArrayList ar = Parent.Operators;
+                       if (ar != null) {
+                               int arLen = ar.Count;
+
+                               for (int i = 0; i < arLen; i++) {
+                                       Operator o = (Operator) ar [i];
+                                       if (IsDuplicateImplementation (o))
+                                               return false;
+                               }
+                       }
 
+                       ar = Parent.Methods;
+                       if (ar != null) {
+                               int arLen = ar.Count;
+
+                               for (int i = 0; i < arLen; i++) {
+                                       Method m = (Method) ar [i];
+                                       if (IsDuplicateImplementation (m))
+                                               return false;
+                               }
+                       }
+
+                       return true;
+               }
+
+               public override bool Define ()
+               {
                        if ((ModFlags & RequiredModifiers) != RequiredModifiers){
                                Report.Error (
                                        558, Location, 
                                        "User defined operators `" +
-                                       Prototype (Parent) +
+                                       GetSignatureForError (Parent) +
                                        "' must be declared static and public");
                                return false;
                        }
 
-                       param_list[0] = new Parameter (FirstArgType, FirstArgName,
-                                                      Parameter.Modifier.NONE, null);
-                       if (SecondArgType != null)
-                               param_list[1] = new Parameter (SecondArgType, SecondArgName,
-                                                              Parameter.Modifier.NONE, null);
-                       
+                       if (!DoDefine (ds))
+                               return false;
+
                        OperatorMethod = new Method (
-                               Parent, null, ReturnType, ModFlags, false,
-                               new MemberName (MethodName),
-                               new Parameters (param_list, null, Location),
-                               OptAttributes, Location);
+                               Parent, null, Type, ModFlags, false, MemberName,
+                               Parameters, OptAttributes, Location);
 
                        OperatorMethod.Block = Block;
                        OperatorMethod.IsOperator = true;                       
-                       OperatorMethod.Define ();
                        OperatorMethod.flags |= MethodAttributes.SpecialName | MethodAttributes.HideBySig;
+                       OperatorMethod.Define ();
 
                        if (OperatorMethod.MethodBuilder == null)
                                return false;
                        
                        OperatorMethodBuilder = OperatorMethod.MethodBuilder;
 
-                       Type [] param_types = OperatorMethod.ParameterTypes;
+                       parameter_types = OperatorMethod.ParameterTypes;
                        Type declaring_type = OperatorMethod.MethodData.DeclaringType;
-                       Type return_type = OperatorMethod.GetReturnType ();
-                       Type first_arg_type = param_types [0];
+                       Type return_type = OperatorMethod.ReturnType;
+                       Type first_arg_type = parameter_types [0];
+
+                       if (!CheckBase ())
+                               return false;
 
                        // Rules for conversion operators
                        
@@ -7055,7 +7132,12 @@ namespace Mono.CSharp {
                                        Report.Error (554, Location, "'{0}' : user defined conversion to/from derived class", GetSignatureForError ());
                                        return false;
                                }
-                       } else if (SecondArgType == null) {
+                       } else if (OperatorType == OpType.LeftShift || OperatorType == OpType.RightShift) {
+                               if (first_arg_type != declaring_type || parameter_types [1] != TypeManager.int32_type) {
+                                       Report.Error (564, Location, "Overloaded shift operator must have the type of the first operand be the containing type, and the type of the second operand must be int");
+                                       return false;
+                               }
+                       } else if (Parameters.FixedParameters.Length == 1) {
                                // Checks for Unary operators
                                
                                if (first_arg_type != declaring_type){
@@ -7091,7 +7173,7 @@ namespace Mono.CSharp {
                                // Checks for Binary operators
                                
                                if (first_arg_type != declaring_type &&
-                                   param_types [1] != declaring_type){
+                                   parameter_types [1] != declaring_type){
                                        Report.Error (
                                                563, Location,
                                                "One of the parameters of a binary operator must " +
@@ -7115,6 +7197,12 @@ namespace Mono.CSharp {
                        Block = null;
                }
 
+               // Operator cannot be override
+               protected override MethodInfo FindOutParentMethod (TypeContainer container, ref Type parent_ret_type)
+               {
+                       return null;
+               }
+
                public static string GetName (OpType ot)
                {
                        switch (ot){
@@ -7174,22 +7262,33 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override string GetSignatureForError(TypeContainer tc)
+               public override string GetSignatureForError (TypeContainer tc)
                {
-                       return ToString ();
+                       StringBuilder sb = new StringBuilder ();
+                       sb.AppendFormat ("{0}.operator {1} {2}({3}", tc.Name, GetName (OperatorType), Type.ToString (), Parameters.FixedParameters [0].GetSignatureForError ());
+                       
+                       if (Parameters.FixedParameters.Length > 1) {
+                               sb.Append (",");
+                               sb.Append (Parameters.FixedParameters [1].GetSignatureForError ());
+                       }
+                       sb.Append (")");
+                       return sb.ToString ();
                }
 
-               public override string GetSignatureForError()
+               public override string GetSignatureForError ()
                {
                        return ToString ();
                }
                
                public override string ToString ()
                {
-                       Type return_type = OperatorMethod.GetReturnType();
+                       if (OperatorMethod == null)
+                               return Name;
+
+                       Type return_type = OperatorMethod.ReturnType;
                        Type [] param_types = OperatorMethod.ParameterTypes;
                        
-                       if (SecondArgType == null)
+                       if (Parameters.FixedParameters.Length == 1)
                                return String.Format (
                                        "{0} operator {1}({2})",
                                        TypeManager.CSharpName (return_type),