Nothing to see here
[mono.git] / mcs / mcs / class.cs
index 3659320ee7bee3613970af6eaf92f8c1d32cf41c..190d85ad164e2f49e5af802165282816478ebda6 100644 (file)
@@ -299,6 +299,11 @@ namespace Mono.CSharp {
                        return AddToContainer (ds, ds.Basename);
                }
 
+               protected virtual void RemoveMemberType (DeclSpace ds)
+               {
+                       RemoveFromContainer (ds.Basename);
+               }
+
                public void AddConstant (Const constant)
                {
                        if (!AddMember (constant))
@@ -380,6 +385,13 @@ namespace Mono.CSharp {
                        return tc;
                }
 
+               public virtual void RemoveTypeContainer (TypeContainer next_part)
+               {
+                       if (types != null)
+                               types.Remove (next_part);
+                       RemoveMemberType (next_part);
+               }
+               
                public void AddDelegate (Delegate d)
                {
                        if (!AddMemberType (d))
@@ -431,16 +443,12 @@ namespace Mono.CSharp {
 
                public void AddConstructor (Constructor c)
                {
-                       if (c.Name != MemberName.Name) {
-                               Report.Error (1520, c.Location, "Class, struct, or interface method must have a return type");
-                       }
-
                        bool is_static = (c.ModFlags & Modifiers.STATIC) != 0;
                        if (!AddToContainer (c, is_static ?
                                ConstructorBuilder.ConstructorName : ConstructorBuilder.TypeConstructorName))
                                return;
                        
-                       if (is_static && c.Parameters.Empty){
+                       if (is_static && c.Parameters.IsEmpty){
                                if (default_static_constructor != null) {
                                    Report.SymbolRelatedToPreviousError (default_static_constructor);
                                        Report.Error (111, c.Location,
@@ -451,7 +459,7 @@ namespace Mono.CSharp {
 
                                default_static_constructor = c;
                        } else {
-                               if (c.Parameters.Empty)
+                               if (c.Parameters.IsEmpty)
                                        default_constructor = c;
                                
                                if (instance_constructors == null)
@@ -681,19 +689,12 @@ namespace Mono.CSharp {
 
                public void ResolveFieldInitializers (EmitContext ec)
                {
-                       // Field initializers are tricky for partial classes. They have to
-                       // share same costructor (block) but they have they own resolve scope.
-                       DeclSpace orig = ec.DeclContainer;
-
                        if (partial_parts != null) {
                                foreach (TypeContainer part in partial_parts) {
-                                       ec.DeclContainer = part;
                                        part.DoResolveFieldInitializers (ec);
                                }
                        }
-                       ec.DeclContainer = PartialContainer;
                        DoResolveFieldInitializers (ec);
-                       ec.DeclContainer = orig; 
                }
 
                void DoResolveFieldInitializers (EmitContext ec)
@@ -702,28 +703,32 @@ namespace Mono.CSharp {
                                if (initialized_static_fields == null)
                                        return;
 
-                               bool has_complex_initializer = false;
-                               using (ec.Set (EmitContext.Flags.InFieldInitializer)) {
-                                       foreach (FieldInitializer fi in initialized_static_fields) {
-                                               fi.ResolveStatement (ec);
-                                               if (!fi.IsComplexInitializer)
-                                                       continue;
-
-                                               has_complex_initializer = true;
+                               bool has_complex_initializer = !RootContext.Optimize;
+                               int i;
+                               ExpressionStatement [] init = new ExpressionStatement [initialized_static_fields.Count];
+                               for (i = 0; i < initialized_static_fields.Count; ++i) {
+                                       FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
+                                       ExpressionStatement s = fi.ResolveStatement (ec);
+                                       if (s == null) {
+                                               s = EmptyExpressionStatement.Instance;
+                                       } else if (fi.IsComplexInitializer) {
+                                               has_complex_initializer |= true;
                                        }
 
+                                       init [i] = s;
+                               }
+
+                               for (i = 0; i < initialized_static_fields.Count; ++i) {
+                                       FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
+                                       //
                                        // Need special check to not optimize code like this
                                        // static int a = b = 5;
                                        // static int b = 0;
-                                       if (!has_complex_initializer && RootContext.Optimize) {
-                                               for (int i = 0; i < initialized_static_fields.Count; ++i) {
-                                                       FieldInitializer fi = (FieldInitializer) initialized_static_fields [i];
-                                                       if (fi.IsDefaultInitializer) {
-                                                               initialized_static_fields.RemoveAt (i);
-                                                               --i;
-                                                       }
-                                               }
-                                       }
+                                       //
+                                       if (!has_complex_initializer && fi.IsDefaultInitializer)
+                                               continue;
+
+                                       ec.CurrentBlock.AddScopeStatement (new StatementExpression (init [i]));
                                }
 
                                return;
@@ -732,16 +737,19 @@ namespace Mono.CSharp {
                        if (initialized_fields == null)
                                return;
 
-                       using (ec.Set (EmitContext.Flags.InFieldInitializer)) {
-                               for (int i = 0; i < initialized_fields.Count; ++i) {
-                                       FieldInitializer fi = (FieldInitializer) initialized_fields [i];
-                                       fi.ResolveStatement (ec);
-                                       if (fi.IsDefaultInitializer && RootContext.Optimize) {
-                                               // Field is re-initialized to its default value => removed
-                                               initialized_fields.RemoveAt (i);
-                                               --i;
-                                       }
-                               }
+                       for (int i = 0; i < initialized_fields.Count; ++i) {
+                               FieldInitializer fi = (FieldInitializer) initialized_fields [i];
+                               ExpressionStatement s = fi.ResolveStatement (ec);
+                               if (s == null)
+                                       continue;
+
+                               //
+                               // Field is re-initialized to its default value => removed
+                               //
+                               if (fi.IsDefaultInitializer && RootContext.Optimize)
+                                       continue;
+
+                               ec.CurrentBlock.AddScopeStatement (new StatementExpression (s));
                        }
                }
 
@@ -803,45 +811,77 @@ namespace Mono.CSharp {
                        ((TypeContainer) part).type_bases = bases;
                }
 
-               TypeExpr[] GetNormalBases (out TypeExpr base_class)
+               /// <summary>
+               ///   This function computes the Base class and also the
+               ///   list of interfaces that the class or struct @c implements.
+               ///   
+               ///   The return value is an array (might be null) of
+               ///   interfaces implemented (as Types).
+               ///   
+               ///   The @base_class argument is set to the base object or null
+               ///   if this is `System.Object'. 
+               /// </summary>
+               protected virtual TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
                {
                        base_class = null;
                        if (type_bases == null)
                                return null;
 
                        int count = type_bases.Count;
-                       int start = 0, i, j;
+                       TypeExpr [] ifaces = null;
+                       for (int i = 0, j = 0; i < count; i++){
+                               FullNamedExpression fne = (FullNamedExpression) type_bases [i];
 
-                       if (Kind == Kind.Class){
-                               TypeExpr name = ((Expression) type_bases [0]).ResolveAsBaseTerminal (this, false);
+                               //
+                               // Standard ResolveAsTypeTerminal cannot be used in this case because
+                               // it does ObsoleteAttribute and constraint checks which require
+                               // base type to be set
+                               //
+                               TypeExpr fne_resolved = fne.ResolveAsBaseTerminal (this, false);
+                               if (fne_resolved == null)
+                                       continue;
 
-                               if (name == null){
-                                       return null;
+                               if (i == 0 && Kind == Kind.Class && !fne_resolved.Type.IsInterface) {
+                                       base_class = fne_resolved;
+                                       continue;
                                }
 
-                               if (!name.IsInterface) {
-                                       // base_class could be a class, struct, enum, delegate.
-                                       // This is validated in GetClassBases.
-                                       base_class = name;
-                                       start = 1;
-                               }
-                       }
+                               if (ifaces == null)
+                                       ifaces = new TypeExpr [count - i];
+
+                               if (fne_resolved.Type.IsInterface) {
+                                       for (int ii = 0; ii < j; ++ii) {
+                                               if (TypeManager.IsEqual (fne_resolved.Type, ifaces [ii].Type)) {
+                                                       Report.Error (528, Location, "`{0}' is already listed in interface list",
+                                                               fne_resolved.GetSignatureForError ());
+                                                       break;
+                                               }
+                                       }
 
-                       TypeExpr [] ifaces = new TypeExpr [count-start];
-                       
-                       for (i = start, j = 0; i < count; i++, j++){
-                               TypeExpr resolved = ((Expression) type_bases [i]).ResolveAsBaseTerminal (this, false);
-                               if (resolved == null) {
-                                       return null;
+                                       if (Kind == Kind.Interface && !fne_resolved.AsAccessible (this)) {
+                                               Report.Error (61, fne.Location,
+                                                       "Inconsistent accessibility: base interface `{0}' is less accessible than interface `{1}'",
+                                                       fne_resolved.GetSignatureForError (), GetSignatureForError ());
+                                       }
+                               } else {
+                                       Report.SymbolRelatedToPreviousError (fne_resolved.Type);
+                                       if (Kind != Kind.Class) {
+                                               Report.Error (527, fne.Location, "Type `{0}' in interface list is not an interface", fne_resolved.GetSignatureForError ());
+                                       } else if (base_class != null)
+                                               Report.Error (1721, fne.Location, "`{0}': Classes cannot have multiple base classes (`{1}' and `{2}')",
+                                                       GetSignatureForError (), base_class.GetSignatureForError (), fne_resolved.GetSignatureForError ());
+                                       else {
+                                               Report.Error (1722, fne.Location, "`{0}': Base class `{1}' must be specified as first",
+                                                       GetSignatureForError (), fne_resolved.GetSignatureForError ());
+                                       }
                                }
-                               
-                               ifaces [j] = resolved;
+
+                               ifaces [j++] = fne_resolved;
                        }
 
-                       return ifaces.Length == 0 ? null : ifaces;
+                       return ifaces;
                }
 
-
                TypeExpr[] GetNormalPartialBases (ref TypeExpr base_class)
                {
                        ArrayList ifaces = new ArrayList (0);
@@ -850,7 +890,7 @@ namespace Mono.CSharp {
 
                        foreach (TypeContainer part in partial_parts) {
                                TypeExpr new_base_class;
-                               TypeExpr[] new_ifaces = part.GetClassBases (out new_base_class);
+                               TypeExpr[] new_ifaces = part.ResolveBaseTypes (out new_base_class);
                                if (new_base_class != TypeManager.system_object_expr) {
                                        if (base_class == TypeManager.system_object_expr)
                                                base_class = new_base_class;
@@ -883,65 +923,6 @@ namespace Mono.CSharp {
                        return (TypeExpr[])ifaces.ToArray (typeof (TypeExpr));
                }
 
-               /// <summary>
-               ///   This function computes the Base class and also the
-               ///   list of interfaces that the class or struct @c implements.
-               ///   
-               ///   The return value is an array (might be null) of
-               ///   interfaces implemented (as Types).
-               ///   
-               ///   The @base_class argument is set to the base object or null
-               ///   if this is `System.Object'. 
-               /// </summary>
-               public virtual TypeExpr [] GetClassBases (out TypeExpr base_class)
-               {
-                       TypeExpr[] ifaces = GetNormalBases (out base_class);
-
-                       if (ifaces == null)
-                               return null;
-
-                       int count = ifaces.Length;
-
-                       for (int i = 0; i < count; i++) {
-                               TypeExpr iface = (TypeExpr) ifaces [i];
-
-                               if (!iface.IsInterface) {
-                                       if (Kind != Kind.Class) {
-                                               // TODO: location of symbol related ....
-                                               Error_TypeInListIsNotInterface (Location, iface.GetSignatureForError ());
-                                       }
-                                       else if (base_class != null)
-                                               Report.Error (1721, Location, "`{0}': Classes cannot have multiple base classes (`{1}' and `{2}')",
-                                                       GetSignatureForError (), base_class.GetSignatureForError (), iface.GetSignatureForError ());
-                                       else {
-                                               Report.Error (1722, Location, "`{0}': Base class `{1}' must be specified as first",
-                                                       GetSignatureForError (), iface.GetSignatureForError ());
-                                       }
-                                       return null;
-                               }
-
-                               for (int x = 0; x < i; x++) {
-                                       if (iface.Equals (ifaces [x])) {
-                                               Report.Error (528, Location,
-                                                             "`{0}' is already listed in " +
-                                                             "interface list", iface.GetSignatureForError ());
-                                               return null;
-                                       }
-                               }
-
-                               if ((Kind == Kind.Interface) &&
-                                   !iface.AsAccessible (this)) {
-                                       Report.Error (61, Location,
-                                                     "Inconsistent accessibility: base " +
-                                                     "interface `{0}' is less accessible " +
-                                                     "than interface `{1}'", iface.GetSignatureForError (),
-                                                     Name);
-                                       return null;
-                               }
-                       }
-                       return ifaces;
-               }
-
                bool CheckGenericInterfaces (Type[] ifaces)
                {
 #if GMCS_SOURCE
@@ -974,11 +955,6 @@ namespace Mono.CSharp {
 
                bool error = false;
                
-               protected void Error_TypeInListIsNotInterface (Location loc, string type)
-               {
-                       Report.Error (527, loc, "Type `{0}' in interface list is not an interface", type);
-               }
-
                bool CreateTypeBuilder ()
                {
                        try {
@@ -1033,7 +1009,7 @@ namespace Mono.CSharp {
 
                bool DefineBaseTypes ()
                {
-                       iface_exprs = GetClassBases (out base_type);
+                       iface_exprs = ResolveBaseTypes (out base_type);
                        if (partial_parts != null) {
                                iface_exprs = GetNormalPartialBases (ref base_type);
                        }
@@ -1051,22 +1027,11 @@ namespace Mono.CSharp {
                        if (!(this is CompilerGeneratedClass))
                                RootContext.RegisterOrder (this); 
 
-                       if (IsGeneric && base_type != null && TypeManager.IsAttributeType (base_type.Type)) {
-                               Report.Error (698, base_type.Location,
-                                             "A generic type cannot derive from `{0}' because it is an attribute class",
-                                             base_type.GetSignatureForError ());
-                               return false;
-                       }
-
                        if (!CheckRecursiveDefinition (this))
                                return false;
 
                        if (base_type != null && base_type.Type != null) {
                                TypeBuilder.SetParent (base_type.Type);
-
-                               ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
-                               if (obsolete_attr != null && !IsInObsoleteScope)
-                                       AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
                        }
 
                        // add interfaces that were not added at type creation
@@ -1078,13 +1043,6 @@ namespace Mono.CSharp {
                                foreach (Type itype in ifaces)
                                        TypeBuilder.AddInterfaceImplementation (itype);
 
-                               foreach (TypeExpr ie in iface_exprs) {
-                                       ObsoleteAttribute oa = AttributeTester.GetObsoleteAttribute (ie.Type);
-                                       if ((oa != null) && !IsInObsoleteScope)
-                                               AttributeTester.Report_ObsoleteMessage (
-                                                       oa, ie.GetSignatureForError (), Location);
-                               }
-
                                if (!CheckGenericInterfaces (ifaces))
                                        return false;
 
@@ -1278,23 +1236,13 @@ namespace Mono.CSharp {
                        }
 
                        current_type = new ConstructedType (TypeBuilder, TypeParameters, Location);
-
-                       foreach (TypeParameter type_param in TypeParameters)
-                               if (!type_param.CheckDependencies ()) {
-                                       error = true;
-                                       return false;
-                               }
-
-                       if (current_type != null) {
-                               current_type = current_type.ResolveAsTypeTerminal (this, false);
-                               if (current_type == null) {
-                                       error = true;
-                                       return false;
-                               }
-
-                               CurrentType = current_type.Type;
+                       current_type = current_type.ResolveAsTypeTerminal (this, false);
+                       if (current_type == null) {
+                               error = true;
+                               return false;
                        }
 
+                       CurrentType = current_type.Type;
                        return true;
                }
 
@@ -1359,22 +1307,14 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public static void Error_KeywordNotAllowed (Location loc)
-               {
-                       Report.Error (1530, loc, "Keyword `new' is not allowed on namespace elements");
-               }
-
                /// <summary>
                ///   Populates our TypeBuilder with fields and methods
                /// </summary>
-               public override bool DefineMembers ()
+               public override bool Define ()
                {
                        if (members_defined)
                                return members_defined_ok;
 
-                       if (!base.DefineMembers ())
-                               return false;
-
                        members_defined_ok = DoDefineMembers ();
                        members_defined = true;
 
@@ -1385,6 +1325,11 @@ namespace Mono.CSharp {
                {
                        if (iface_exprs != null) {
                                foreach (TypeExpr iface in iface_exprs) {
+                                       ObsoleteAttribute oa = AttributeTester.GetObsoleteAttribute (iface.Type);
+                                       if ((oa != null) && !IsInObsoleteScope)
+                                               AttributeTester.Report_ObsoleteMessage (
+                                                       oa, iface.GetSignatureForError (), Location);
+
                                        ConstructedType ct = iface as ConstructedType;
                                        if ((ct != null) && !ct.CheckConstraints (this))
                                                return false;
@@ -1392,6 +1337,10 @@ namespace Mono.CSharp {
                        }
 
                        if (base_type != null) {
+                               ObsoleteAttribute obsolete_attr = AttributeTester.GetObsoleteAttribute (base_type.Type);
+                               if (obsolete_attr != null && !IsInObsoleteScope)
+                                       AttributeTester.Report_ObsoleteMessage (obsolete_attr, base_type.GetSignatureForError (), Location);
+
                                ConstructedType ct = base_type as ConstructedType;
                                if ((ct != null) && !ct.CheckConstraints (this))
                                        return false;
@@ -1549,12 +1498,6 @@ namespace Mono.CSharp {
                        }
                }
 
-               public override bool Define ()
-               {
-                       CheckProtectedModifier ();
-                       return true;
-               }
-
                public MemberInfo FindBaseMemberWithSameName (string name, bool ignore_methods)
                {
                        return BaseCache == null ? null : BaseCache.FindMemberWithSameName (name, ignore_methods, null);
@@ -1584,7 +1527,7 @@ namespace Mono.CSharp {
                {
                        ArrayList members = new ArrayList ();
 
-                       DefineMembers ();
+                       Define ();
 
                        if (methods != null) {
                                int len = methods.Count;
@@ -1651,6 +1594,11 @@ namespace Mono.CSharp {
                        set { caching_flags |= Flags.HasExplicitLayout; }
                }
 
+               public bool HasStructLayout {
+                       get { return (caching_flags & Flags.HasStructLayout) != 0; }
+                       set { caching_flags |= Flags.HasStructLayout; }
+               }
+
                //
                // Return the nested type with name @name.  Ensures that the nested type
                // is defined if necessary.  Do _not_ use this when you have a MemberCache handy.
@@ -2148,6 +2096,12 @@ namespace Mono.CSharp {
                                                
                                                if ((f.caching_flags & Flags.IsAssigned) != 0)
                                                        continue;
+
+                                               //
+                                               // Don't be pendatic over serializable attributes
+                                               //
+                                               if (f.OptAttributes != null || PartialContainer.HasStructLayout)
+                                                       continue;
                                                
                                                Constant c = New.Constantify (f.MemberType);
                                                Report.Warning (649, 4, f.Location, "Field `{0}' is never assigned to, and will always have its default value `{1}'",
@@ -2249,8 +2203,7 @@ namespace Mono.CSharp {
                        }
 
                        if (pending != null)
-                               if (pending.VerifyPendingMethods ())
-                                       return;
+                               pending.VerifyPendingMethods ();
 
                        if (Report.Errors > 0)
                                return;
@@ -2652,8 +2605,11 @@ namespace Mono.CSharp {
                                return;
                        }
 
-                       if (a.Type == TypeManager.struct_layout_attribute_type && a.GetLayoutKindValue () == LayoutKind.Explicit) {
-                               PartialContainer.HasExplicitLayout = true;
+                       if (a.Type == TypeManager.struct_layout_attribute_type) {
+                               PartialContainer.HasStructLayout = true;
+
+                               if (a.GetLayoutKindValue () == LayoutKind.Explicit)
+                                       PartialContainer.HasExplicitLayout = true;
                        }
 
                        base.ApplyAttributeBuilder (a, cb);
@@ -2676,7 +2632,7 @@ namespace Mono.CSharp {
                        }
 
                        Constructor c = new Constructor (this, MemberName.Name, mods,
-                               Parameters.EmptyReadOnlyParameters,
+                               null, Parameters.EmptyReadOnlyParameters,
                                new GeneratedBaseInitializer (Location),
                                Location);
                        
@@ -2686,17 +2642,23 @@ namespace Mono.CSharp {
 
                public override bool Define ()
                {
-                       if (default_static_constructor == null && PartialContainer.HasStaticFieldInitializer)
-                               DefineDefaultConstructor (true);
+                       CheckProtectedModifier ();
+
+                       base.Define ();
 
                        if (default_static_constructor != null)
                                default_static_constructor.Define ();
 
-                       return base.Define ();
+                       return true;
                }
 
                public override void Emit ()
                {
+                       if (default_static_constructor == null && PartialContainer.HasStaticFieldInitializer) {
+                               DefineDefaultConstructor (true);
+                               default_static_constructor.Define ();
+                       }
+
                        base.Emit ();
 
                        if (declarative_security != null) {
@@ -2815,11 +2777,6 @@ namespace Mono.CSharp {
                                        continue;
                                }
 
-                               if ((m.ModFlags & Modifiers.PROTECTED) != 0) {
-                                       m.CheckProtectedModifier ();
-                                       continue;
-                               }
-
                                if (m is Indexer) {
                                        Report.Error (720, m.Location, "`{0}': cannot declare indexers in a static class", m.GetSignatureForError ());
                                        continue;
@@ -2845,19 +2802,17 @@ namespace Mono.CSharp {
                        base.DefineContainerMembers (list);
                }
 
-               public override TypeBuilder DefineType ()
+               public override bool Define ()
                {
                        if ((ModFlags & Modifiers.ABSTRACT) == Modifiers.ABSTRACT && (ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) != 0) {
                                Report.Error (418, Location, "`{0}': an abstract class cannot be sealed or static", GetSignatureForError ());
-                               return null;
                        }
 
                        if ((ModFlags & (Modifiers.SEALED | Modifiers.STATIC)) == (Modifiers.SEALED | Modifiers.STATIC)) {
                                Report.Error (441, Location, "`{0}': a class cannot be both static and sealed", GetSignatureForError ());
-                               return null;
                        }
 
-                       return base.DefineType ();
+                       return base.Define ();
                }
 
                protected override bool DoDefineMembers ()
@@ -2878,9 +2833,9 @@ namespace Mono.CSharp {
 #endif                 
                }
 
-               public override TypeExpr[] GetClassBases (out TypeExpr base_class)
+               protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
                {
-                       TypeExpr[] ifaces = base.GetClassBases (out base_class);
+                       TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);
 
                        if (base_class == null) {
                                if (RootContext.StdLib)
@@ -2896,6 +2851,12 @@ namespace Mono.CSharp {
                                        return ifaces;
                                }
 
+                               if (IsGeneric && TypeManager.IsAttributeType (base_class.Type)) {
+                                       Report.Error (698, base_class.Location,
+                                               "A generic type cannot derive from `{0}' because it is an attribute class",
+                                               base_class.GetSignatureForError ());
+                               }
+
                                if (base_class.IsSealed){
                                        Report.SymbolRelatedToPreviousError (base_class.Type);
                                        if (base_class.Type.IsAbstract) {
@@ -3016,21 +2977,33 @@ namespace Mono.CSharp {
                        this.ModFlags |= Modifiers.SEALED;
                }
 
+               public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
+               {
+                       base.ApplyAttributeBuilder (a, cb);
+
+                       //
+                       // When struct constains fixed fixed and struct layout has explicitly
+                       // set CharSet, its value has to be propagated to compiler generated
+                       // fixed field types
+                       //
+                       if (a.Type == TypeManager.struct_layout_attribute_type && Fields != null && a.HasField ("CharSet")) {
+                               for (int i = 0; i < Fields.Count; ++i) {
+                                       FixedField ff = Fields [i] as FixedField;
+                                       if (ff != null)
+                                               ff.SetCharSet (TypeBuilder.Attributes);
+                               }
+                       }
+               }
+
                public override AttributeTargets AttributeTargets {
                        get {
                                return AttributeTargets.Struct;
                        }
                }
 
-               const TypeAttributes DefaultTypeAttributes =
-                       TypeAttributes.SequentialLayout |
-                       TypeAttributes.Sealed |
-                       TypeAttributes.BeforeFieldInit;
-
-
-               public override TypeExpr[] GetClassBases (out TypeExpr base_class)
+               protected override TypeExpr[] ResolveBaseTypes (out TypeExpr base_class)
                {
-                       TypeExpr[] ifaces = base.GetClassBases (out base_class);
+                       TypeExpr[] ifaces = base.ResolveBaseTypes (out base_class);
                        //
                        // If we are compiling our runtime,
                        // and we are defining ValueType, then our
@@ -3053,6 +3026,11 @@ namespace Mono.CSharp {
                //
                protected override TypeAttributes TypeAttr {
                        get {
+                               const TypeAttributes DefaultTypeAttributes =
+                                       TypeAttributes.SequentialLayout |
+                                       TypeAttributes.Sealed |
+                                       TypeAttributes.BeforeFieldInit;
+
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
@@ -3116,13 +3094,13 @@ namespace Mono.CSharp {
                        }
                }
 
-               const TypeAttributes DefaultTypeAttributes =
-                       TypeAttributes.AutoLayout |
-                       TypeAttributes.Abstract |
-                       TypeAttributes.Interface;
-
                protected override TypeAttributes TypeAttr {
                        get {
+                               const TypeAttributes DefaultTypeAttributes =
+                                       TypeAttributes.AutoLayout |
+                                       TypeAttributes.Abstract |
+                                       TypeAttributes.Interface;
+
                                return base.TypeAttr | DefaultTypeAttributes;
                        }
                }
@@ -3401,7 +3379,7 @@ namespace Mono.CSharp {
                        }
 
                        if ((ModFlags & Modifiers.NEW) == 0) {
-                               if (this is Method && conflict_symbol is MethodBase)
+                               if (this is MethodOrOperator && conflict_symbol.MemberType == MemberTypes.Method)
                                        return true;
 
                                Report.SymbolRelatedToPreviousError (conflict_symbol);
@@ -3530,25 +3508,25 @@ namespace Mono.CSharp {
                                return false;
 
                        bool error = false;
-                       foreach (Parameter p in parameters.FixedParameters) {
+                       for (int i = 0; i < parameters.Count; ++i) {
+                               Parameter p = parameters [i];
                                if (p.CheckAccessibility (this))
                                        continue;
 
-                               Report.SymbolRelatedToPreviousError (p.ParameterType);
+                               Type t = parameters.Types [i];
+                               Report.SymbolRelatedToPreviousError (t);
                                if (this is Indexer)
                                        Report.Error (55, Location,
-                                               "Inconsistent accessibility: parameter type `" +
-                                               TypeManager.CSharpName (p.ParameterType) + "' is less " +
-                                               "accessible than indexer `" + GetSignatureForError () + "'");
+                                                     "Inconsistent accessibility: parameter type `{0}' is less accessible than indexer `{1}'",
+                                                     TypeManager.CSharpName (t), GetSignatureForError ());
                                else if (this is Operator)
                                        Report.Error (57, Location,
-                                               "Inconsistent accessibility: parameter type `" +
-                                               TypeManager.CSharpName (p.ParameterType) + "' is less " +
-                                               "accessible than operator `" + GetSignatureForError () + "'");
+                                                     "Inconsistent accessibility: parameter type `{0}' is less accessible than operator `{1}'",
+                                                     TypeManager.CSharpName (t), GetSignatureForError ());
                                else
                                        Report.Error (51, Location,
                                                "Inconsistent accessibility: parameter type `{0}' is less accessible than method `{1}'",
-                                               TypeManager.CSharpName (p.ParameterType), GetSignatureForError ());
+                                               TypeManager.CSharpName (t), GetSignatureForError ());
                                error = true;
                        }
                        return !error;
@@ -3805,7 +3783,7 @@ namespace Mono.CSharp {
 
                        if ((ModFlags & Modifiers.PARTIAL) != 0) {
                                for (int i = 0; i < Parameters.Count; ++i ) {
-                                       if (Parameters.ParameterModifier (i) == Parameter.Modifier.OUT) {
+                                       if (Parameters.FixedParameters [i].ModFlags == Parameter.Modifier.OUT) {
                                                Report.Error (752, Location, "`{0}': A partial method parameters cannot use `out' modifier",
                                                        GetSignatureForError ());
                                                return false;
@@ -3816,8 +3794,14 @@ namespace Mono.CSharp {
                        if (!CheckBase ())
                                return false;
 
-                       if (block != null && block.IsIterator && !(Parent is IteratorStorey))
+                       if (block != null && block.IsIterator && !(Parent is IteratorStorey)) {
+                               //
+                               // Current method is turned into automatically generated
+                               // wrapper which creates an instance of iterator
+                               //
                                Iterator.CreateIterator (this, Parent.PartialContainer, ModFlags);
+                               ModFlags |= Modifiers.DEBUGGER_HIDDEN;
+                       }
 
                        if (IsPartialDefinition) {
                                caching_flags &= ~Flags.Excluded_Undetected;
@@ -4125,7 +4109,7 @@ namespace Mono.CSharp {
                        if (Parameters.Count > 1)
                                return false;
 
-                       Type t = Parameters.ParameterType (0);
+                       Type t = Parameters.Types [0];
                        return t.IsArray && t.GetArrayRank () == 1 &&
                                        TypeManager.GetElementType (t) == TypeManager.string_type &&
                                        (Parameters[0].ModFlags & ~Parameter.Modifier.PARAMS) == Parameter.Modifier.NONE;
@@ -4162,7 +4146,7 @@ namespace Mono.CSharp {
                                }
 
                                for (int i = 0; i < Parameters.Count; ++i) {
-                                       if ((Parameters.ParameterModifier (i) & Parameter.Modifier.OUTMASK) != 0) {
+                                       if (Parameters.FixedParameters [i].ModFlags == Parameter.Modifier.OUT) {
                                                Report.Error (685, Location, "Conditional method `{0}' cannot have an out parameter", GetSignatureForError ());
                                                return;
                                        }
@@ -4208,12 +4192,12 @@ namespace Mono.CSharp {
                        if (!base.Define ())
                                return false;
 
-                       if (RootContext.StdLib && (ReturnType == TypeManager.arg_iterator_type || ReturnType == TypeManager.typed_reference_type)) {
+                       if (RootContext.StdLib && TypeManager.IsSpecialType (ReturnType)) {
                                Error1599 (Location, ReturnType);
                                return false;
                        }
 
-                       if (ReturnType == TypeManager.void_type && ParameterTypes.Length == 0 && 
+                       if (ReturnType == TypeManager.void_type && Parameters.Count == 0 && 
                                Name == "Finalize" && !(this is Destructor)) {
                                Report.Warning (465, 1, Location, "Introducing a 'Finalize' method can interfere with destructor invocation. Did you intend to declare a destructor?");
                        }
@@ -4221,7 +4205,7 @@ namespace Mono.CSharp {
                        if (base_method != null && (ModFlags & Modifiers.NEW) == 0) {
                                if (Parameters.Count == 1 && ParameterTypes [0] == TypeManager.object_type && Name == "Equals")
                                        Parent.PartialContainer.Mark_HasEquals ();
-                               else if (Parameters.Empty && Name == "GetHashCode")
+                               else if (Parameters.IsEmpty && Name == "GetHashCode")
                                        Parent.PartialContainer.Mark_HasGetHashCode ();
                        }
 
@@ -4346,7 +4330,7 @@ namespace Mono.CSharp {
                protected override MethodInfo FindOutBaseMethod (ref Type base_ret_type)
                {
                        MethodInfo mi = (MethodInfo) Parent.PartialContainer.BaseCache.FindMemberToOverride (
-                               Parent.TypeBuilder, Name, ParameterTypes, GenericMethod, false);
+                               Parent.TypeBuilder, Name, Parameters, GenericMethod, false);
 
                        if (mi == null)
                                return null;
@@ -4533,10 +4517,10 @@ namespace Mono.CSharp {
                // The spec claims that static is not permitted, but
                // my very own code has static constructors.
                //
-               public Constructor (DeclSpace parent, string name, int mod, Parameters args,
+               public Constructor (DeclSpace parent, string name, int mod, Attributes attrs, Parameters args,
                                    ConstructorInitializer init, Location loc)
                        : base (parent, null, null, mod, AllowedModifiers,
-                               new MemberName (name, loc), null, args)
+                               new MemberName (name, loc), attrs, args)
                {
                        Initializer = init;
                }
@@ -4555,9 +4539,9 @@ namespace Mono.CSharp {
                public bool IsDefault ()
                {
                        if ((ModFlags & Modifiers.STATIC) != 0)
-                               return Parameters.Empty;
+                               return Parameters.IsEmpty;
                        
-                       return Parameters.Empty &&
+                       return Parameters.IsEmpty &&
                                        (Initializer is ConstructorBaseInitializer) &&
                                        (Initializer.Arguments == null);
                }
@@ -4582,7 +4566,7 @@ namespace Mono.CSharp {
                protected override bool CheckBase ()
                {
                        if ((ModFlags & Modifiers.STATIC) != 0) {
-                               if (!Parameters.Empty) {
+                               if (!Parameters.IsEmpty) {
                                        Report.Error (132, Location, "`{0}': The static constructor must be parameterless",
                                                GetSignatureForError ());
                                        return false;
@@ -4601,7 +4585,7 @@ namespace Mono.CSharp {
                                        Parameters);
 
                        if (Parent.PartialContainer.Kind == Kind.Struct) {
-                               if (ParameterTypes.Length == 0) {
+                               if (Parameters.Count == 0) {
                                        Report.Error (568, Location, 
                                                "Structs cannot contain explicit parameterless constructors");
                                        return false;
@@ -4651,7 +4635,7 @@ namespace Mono.CSharp {
 
                        ConstructorBuilder = Parent.TypeBuilder.DefineConstructor (
                                ca, CallingConventions,
-                               ParameterTypes);
+                               Parameters.GetEmitTypes ());
 
                        if (Parent.PartialContainer.IsComImport) {
                                if (!IsDefault ()) {
@@ -4743,9 +4727,6 @@ namespace Mono.CSharp {
                                if (Report.Errors > 0)
                                        return;
 
-                               if (emit_field_initializers)
-                                       Parent.PartialContainer.EmitFieldInitializers (ec);
-
                                ec.EmitResolvedTopBlock (block, unreachable);
                        }
 
@@ -4790,7 +4771,7 @@ namespace Mono.CSharp {
                                        MemberCache.VerifyClsParameterConflict (al, this, ConstructorBuilder);
  
                                if (TypeManager.IsSubclassOf (Parent.TypeBuilder, TypeManager.attribute_type)) {
-                                       foreach (Type param in ParameterTypes) {
+                                       foreach (Type param in Parameters.Types) {
                                                if (param.IsArray) {
                                                        return true;
                                                }
@@ -5066,7 +5047,7 @@ namespace Mono.CSharp {
                                        flags |= MethodAttributes.Final;
                        }
 
-                       DefineMethodBuilder (container, method_full_name, method.ParameterInfo.Types);
+                       DefineMethodBuilder (container, method_full_name, method.ParameterInfo);
 
                        if (builder == null)
                                return false;
@@ -5108,12 +5089,12 @@ namespace Mono.CSharp {
                /// <summary>
                /// Create the MethodBuilder for the method 
                /// </summary>
-               void DefineMethodBuilder (TypeContainer container, string method_name, Type[] ParameterTypes)
+               void DefineMethodBuilder (TypeContainer container, string method_name, Parameters param)
                {
                        if (builder == null) {
                                builder = container.TypeBuilder.DefineMethod (
                                        method_name, flags, method.CallingConventions,
-                                       method.ReturnType, ParameterTypes);
+                                       method.ReturnType, param.GetEmitTypes ());
                                return;
                        }
 
@@ -5122,7 +5103,7 @@ namespace Mono.CSharp {
                        // Generic method has been already defined to resolve method parameters
                        // correctly when they use type parameters
                        //
-                       builder.SetParameters (ParameterTypes);
+                       builder.SetParameters (param.GetEmitTypes ());
                        builder.SetReturnType (method.ReturnType);
 
                        if (builder.Attributes != flags) {
@@ -5350,7 +5331,7 @@ namespace Mono.CSharp {
 
                protected bool IsTypePermitted ()
                {
-                       if (MemberType == TypeManager.arg_iterator_type || MemberType == TypeManager.typed_reference_type) {
+                       if (TypeManager.IsSpecialType (MemberType)) {
                                Report.Error (610, Location, "Field or property cannot be of type `{0}'", TypeManager.CSharpName (MemberType));
                                return false;
                        }
@@ -5458,12 +5439,6 @@ namespace Mono.CSharp {
                        if (TypeManager.IsGenericParameter (MemberType))
                                return true;
 
-                       if (MemberType == TypeManager.void_type) {
-                               // TODO: wrong location
-                               Expression.Error_VoidInvalidInTheContext (Location);
-                               return false;
-                       }
-
                        if (MemberType.IsSealed && MemberType.IsAbstract) {
                                Error_VariableOfStaticClass (Location, GetSignatureForError (), MemberType);
                                return false;
@@ -5499,8 +5474,8 @@ namespace Mono.CSharp {
                                OptAttributes.Emit ();
                        }
 
-                       if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & Modifiers.STATIC) == 0 && Parent.PartialContainer.HasExplicitLayout) {
-                               Report.Error (625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute.", GetSignatureForError ());
+                       if (((status & Status.HAS_OFFSET) == 0) && (ModFlags & (Modifiers.STATIC | Modifiers.BACKING_FIELD)) == 0 && Parent.PartialContainer.HasExplicitLayout) {
+                               Report.Error (625, Location, "`{0}': Instance field types marked with StructLayout(LayoutKind.Explicit) must have a FieldOffset attribute", GetSignatureForError ());
                        }
 
                        base.Emit ();
@@ -5612,7 +5587,7 @@ namespace Mono.CSharp {
                        Expression size_expr, Attributes attrs, Location loc):
                        base (parent, type, mod, AllowedModifiers, new MemberName (name, loc), attrs)
                {
-                       if (RootContext.Version == LanguageVersion.ISO_1)
+                       if (RootContext.Version < LanguageVersion.ISO_2)
                                Report.FeatureIsNotAvailable (loc, "fixed size buffers");
 
                        this.size_expr = size_expr;
@@ -5633,7 +5608,7 @@ namespace Mono.CSharp {
                        
                        // Create nested fixed buffer container
                        string name = String.Format ("<{0}>__FixedBuffer{1}", Name, GlobalCounter++);
-                       fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name,
+                       fixed_buffer_type = Parent.TypeBuilder.DefineNestedType (name, CodeGen.Module.DefaultCharSetType |
                                TypeAttributes.NestedPublic | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, TypeManager.value_type);
                        
                        element = fixed_buffer_type.DefineField (FixedElementName, MemberType, FieldAttributes.Public);
@@ -5657,8 +5632,8 @@ namespace Mono.CSharp {
                        Constant c = size_expr.ResolveAsConstant (ec, this);
                        if (c == null)
                                return;
-
-                       IntConstant buffer_size_const = c.ImplicitConversionRequired (TypeManager.int32_type, Location) as IntConstant;
+                       
+                       IntConstant buffer_size_const = c.ImplicitConversionRequired (ec, TypeManager.int32_type, Location) as IntConstant;
                        if (buffer_size_const == null)
                                return;
 
@@ -5679,6 +5654,28 @@ namespace Mono.CSharp {
 
                        buffer_size *= type_size;
                        EmitFieldSize (buffer_size);
+
+#if GMCS_SOURCE
+                       //
+                       // Emit compiler generated fixed buffer type attribute
+                       //
+                       CustomAttributeBuilder cab = TypeManager.unsafe_value_type_attr;
+                       if (cab == null) {
+                               Type attr_type = TypeManager.CoreLookupType (
+                                       "System.Runtime.CompilerServices", "UnsafeValueTypeAttribute", Kind.Class, true);
+
+                               if (attr_type != null) {
+                                       ConstructorInfo ci = TypeManager.GetPredefinedConstructor (attr_type, Location);
+                                       if (ci != null) {
+                                               cab = new CustomAttributeBuilder (ci, new object [0]);
+                                               TypeManager.unsafe_value_type_attr = cab;
+                                       }
+                               }
+                       }
+
+                       if (cab != null)
+                               fixed_buffer_type.SetCustomAttribute (cab);
+#endif
                        base.Emit ();
                }
 
@@ -5740,6 +5737,27 @@ namespace Mono.CSharp {
                        }
                }
 
+               public void SetCharSet (TypeAttributes ta)
+               {
+                       TypeAttributes cta = fixed_buffer_type.Attributes;
+                       if ((cta & TypeAttributes.UnicodeClass) != (ta & TypeAttributes.UnicodeClass))
+                               SetTypeBuilderCharSet ((cta & ~TypeAttributes.AutoClass) | TypeAttributes.UnicodeClass);
+                       else if ((cta & TypeAttributes.AutoClass) != (ta & TypeAttributes.AutoClass))
+                               SetTypeBuilderCharSet ((cta & ~TypeAttributes.UnicodeClass) | TypeAttributes.AutoClass);
+                       else if (cta == 0 && ta != 0)
+                               SetTypeBuilderCharSet (cta & ~(TypeAttributes.UnicodeClass | TypeAttributes.AutoClass));
+               }
+
+               void SetTypeBuilderCharSet (TypeAttributes ta)
+               {
+                       MethodInfo mi = typeof (TypeBuilder).GetMethod ("SetCharSet", BindingFlags.Instance | BindingFlags.NonPublic);
+                       if (mi == null) {
+                               Report.RuntimeMissingSupport (Location, "TypeBuilder::SetCharSet");
+                       } else {
+                               mi.Invoke (fixed_buffer_type, new object [] { ta });
+                       }
+               }
+
                #region IFixedField Members
 
                public FieldInfo Element {
@@ -5800,6 +5818,33 @@ namespace Mono.CSharp {
                        return false;
                }
 
+               bool CheckStructLayout (Type type, bool isStatic)
+               {
+                       if (TypeManager.IsBuiltinType (type))
+                               return true;
+
+                       if (isStatic) {
+                               if (!TypeManager.IsValueType (type) || TypeManager.IsEqual (type, Parent.TypeBuilder))
+                                       return true;
+                       }
+
+                       if (!TypeManager.IsEqual (TypeManager.DropGenericTypeArguments (type), Parent.TypeBuilder)) {
+                               if (!TypeManager.IsGenericType (type))
+                                       return true;
+
+                               foreach (Type t in TypeManager.GetTypeArguments (type)) {
+                                       if (!CheckStructLayout (t, false))
+                                               return false;
+                               }
+                               return true;
+                       }
+                       
+                       Report.Error (523, Location,
+                               "Struct member `{0}' of type `{1}' causes a cycle in the struct layout",
+                               GetSignatureForError (), TypeManager.CSharpName (MemberType));
+                       return false;
+               }
+
                public override bool Define ()
                {
                        if (!base.Define ())
@@ -5817,8 +5862,6 @@ namespace Mono.CSharp {
                                }
                        }
 
-                       FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
-
                        try {
 #if GMCS_SOURCE
                                Type[] required_modifier = null;
@@ -5841,19 +5884,16 @@ namespace Mono.CSharp {
                                TypeManager.RegisterFieldBase (FieldBuilder, this);
                        }
                        catch (ArgumentException) {
-                               Report.Warning (-24, 1, Location, "The Microsoft runtime is unable to use [void|void*] as a field type, try using the Mono runtime.");
+                               Report.RuntimeMissingSupport (Location, "`void' or `void*' field type");
                                return false;
                        }
 
-                       if (initializer != null)
+                       if (initializer != null) {
                                ((TypeContainer) Parent).RegisterFieldForInitialization (this,
-                                       new FieldInitializer (FieldBuilder, initializer));
-
-                       if (Parent.PartialContainer.Kind == Kind.Struct && (fa & FieldAttributes.Static) == 0 &&
-                               MemberType == Parent.TypeBuilder && !TypeManager.IsBuiltinType (MemberType) && initializer == null) {
-                               Report.Error (523, Location, "Struct member `{0}' causes a cycle in the structure layout",
-                                       GetSignatureForError ());
-                               return false;
+                                       new FieldInitializer (FieldBuilder, initializer, this));
+                       } else {
+                               if (Parent.PartialContainer.Kind == Kind.Struct)
+                                       CheckStructLayout (member_type, (ModFlags & Modifiers.STATIC) != 0);
                        }
 
                        return true;
@@ -5900,12 +5940,14 @@ namespace Mono.CSharp {
                public Attributes Attributes;
                public Location Location;
                public int ModFlags;
+               public Parameters Parameters;
                
-               public Accessor (ToplevelBlock b, int mod, Attributes attrs, Location loc)
+               public Accessor (ToplevelBlock b, int mod, Attributes attrs, Parameters p, Location loc)
                {
                        Block = b;
                        Attributes = attrs;
                        Location = loc;
+                       Parameters = p;
                        ModFlags = Modifiers.Check (AllowedModifiers, mod, 0, loc);
                }
        }
@@ -6152,14 +6194,11 @@ namespace Mono.CSharp {
 
                        public override MethodBuilder Define (DeclSpace parent)
                        {
-                               if (!CheckForDuplications ())
-                                       return null;
+                               base.Define (parent);
 
                                if (IsDummy)
                                        return null;
                                
-                               base.Define (parent);
-                               
                                method_data = new MethodData (method, ModFlags, flags, this);
 
                                if (!method_data.Define (parent, method.GetFullName (MemberName)))
@@ -6193,14 +6232,17 @@ namespace Mono.CSharp {
                        ImplicitParameter param_attr;
                        protected Parameters parameters;
 
-                       public SetMethod (PropertyBase method):
+                       public SetMethod (PropertyBase method) :
                                base (method, "set_")
                        {
+                               parameters = new Parameters (
+                                       new Parameter (method.type_name, "value", Parameter.Modifier.NONE, null, Location));
                        }
 
                        public SetMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor, "set_")
                        {
+                               this.parameters = accessor.Parameters;
                        }
 
                        protected override void ApplyToExtraTarget(Attribute a, CustomAttributeBuilder cb)
@@ -6217,29 +6259,19 @@ namespace Mono.CSharp {
                        }
 
                        public override Parameters ParameterInfo {
-                               get {
-                                       if (parameters == null)
-                                               DefineParameters ();
-                                       return parameters;
-                               }
-                       }
-
-                       protected virtual void DefineParameters ()
-                       {
-                               parameters = Parameters.CreateFullyResolved (
-                                       new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, Location));
+                           get {
+                               return parameters;
+                           }
                        }
 
                        public override MethodBuilder Define (DeclSpace parent)
                        {
-                               if (!CheckForDuplications ())
-                                       return null;
-                               
+                               parameters.Resolve (ResolveContext);
+                               base.Define (parent);
+
                                if (IsDummy)
                                        return null;
 
-                               base.Define (parent);
-
                                method_data = new MethodData (method, ModFlags, flags, this);
 
                                if (!method_data.Define (parent, method.GetFullName (MemberName)))
@@ -6272,6 +6304,7 @@ namespace Mono.CSharp {
                                : base (method, prefix)
                        {
                                this.method = method;
+                               this.ModFlags = method.ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE);                                
                        }
 
                        public PropertyMethod (PropertyBase method, Accessor accessor,
@@ -6279,7 +6312,7 @@ namespace Mono.CSharp {
                                : base (method, accessor, prefix)
                        {
                                this.method = method;
-                               this.ModFlags = accessor.ModFlags;
+                               this.ModFlags = accessor.ModFlags | (method.ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE));
 
                                if (accessor.ModFlags != 0 && RootContext.Version == LanguageVersion.ISO_1) {
                                        Report.FeatureIsNotAvailable (Location, "access modifiers on properties");
@@ -6308,6 +6341,21 @@ namespace Mono.CSharp {
 
                        public virtual MethodBuilder Define (DeclSpace parent)
                        {
+                               CheckForDuplications ();
+
+                               if (IsDummy) {
+                                       if (method.InterfaceType != null && method.IsExplicitImpl) {
+                                               MethodInfo mi = parent.PartialContainer.PendingImplementations.IsInterfaceMethod (
+                                                       MethodName.Name, method.InterfaceType, new MethodData (method, ModFlags, flags, this));
+                                               if (mi != null) {
+                                                       Report.SymbolRelatedToPreviousError (mi);
+                                                       Report.Error (551, Location, "Explicit interface implementation `{0}' is missing accessor `{1}'",
+                                                               method.GetSignatureForError (), TypeManager.CSharpSignature (mi, true));
+                                               }
+                                       }
+                                       return null;
+                               }
+
                                TypeContainer container = parent.PartialContainer;
 
                                //
@@ -6454,8 +6502,9 @@ namespace Mono.CSharp {
                                return false;
                        }
 
-                       if ((Get.IsDummy || Set.IsDummy)
-                           && (Get.ModFlags != 0 || Set.ModFlags != 0) && (ModFlags & Modifiers.OVERRIDE) == 0) {
+                       if ((ModFlags & Modifiers.OVERRIDE) == 0 && 
+                               (Get.IsDummy && (Set.ModFlags & Modifiers.Accessibility) != 0) ||
+                               (Set.IsDummy && (Get.ModFlags & Modifiers.Accessibility) != 0)) {
                                Report.Error (276, Location, 
                                              "`{0}': accessibility modifiers on accessors may only be used if the property or indexer has both a get and a set accessor",
                                              GetSignatureForError ());
@@ -6650,8 +6699,7 @@ namespace Mono.CSharp {
                        get_block.ModFlags |= Modifiers.COMPILER_GENERATED;
 
                        // Make set block
-                       Parameters parameters = new Parameters (new Parameter (type_name, "value", Parameter.Modifier.NONE, null, Location));
-                       set_block.Block = new ToplevelBlock (block, parameters, Location);
+                       set_block.Block = new ToplevelBlock (block, set_block.Parameters, Location);
                        Assign a = new SimpleAssign (new SimpleName (field.Name, Location), new SimpleName ("value", Location));
                        set_block.Block.AddStatement (new StatementExpression(a));
                        set_block.ModFlags |= Modifiers.COMPILER_GENERATED;
@@ -6728,10 +6776,21 @@ namespace Mono.CSharp {
                        return true;
                }
 
+               public override void Emit ()
+               {
+                       if (((Set.ModFlags | Get.ModFlags) & (Modifiers.STATIC | Modifiers.COMPILER_GENERATED)) == Modifiers.COMPILER_GENERATED && Parent.PartialContainer.HasExplicitLayout) {
+                               Report.Error (842, Location,
+                                       "Automatically implemented property `{0}' cannot be used inside a type with an explicit StructLayout attribute",
+                                       GetSignatureForError ());
+                       }
+
+                       base.Emit ();
+               }
+
                protected override PropertyInfo ResolveBaseProperty ()
                {
                        return Parent.PartialContainer.BaseCache.FindMemberToOverride (
-                               Parent.TypeBuilder, Name, Parameters.EmptyReadOnlyParameters.Types, null, true) as PropertyInfo;
+                               Parent.TypeBuilder, Name, Parameters.EmptyReadOnlyParameters, null, true) as PropertyInfo;
                }
        }
 
@@ -7095,7 +7154,7 @@ namespace Mono.CSharp {
                                }
 
                                ((TypeContainer) Parent).RegisterFieldForInitialization (this,
-                                       new FieldInitializer (FieldBuilder, Initializer));
+                                       new FieldInitializer (FieldBuilder, Initializer, this));
                        }
 
                        return true;
@@ -7280,7 +7339,7 @@ namespace Mono.CSharp {
                        }
 
                        parameters = Parameters.CreateFullyResolved (
-                               new Parameter (MemberType, "value", Parameter.Modifier.NONE, null, Location));
+                               new Parameter (null, "value", Parameter.Modifier.NONE, null, Location), MemberType);
 
                        if (!CheckBase ())
                                return false;
@@ -7339,8 +7398,8 @@ namespace Mono.CSharp {
                        if (mi == null)
                                return null;
 
-                       ParameterData pd = TypeManager.GetParameterData (mi);
-                       base_ret_type = pd.ParameterType (0);
+                       AParametersCollection pd = TypeManager.GetParameterData (mi);
+                       base_ret_type = pd.Types [0];
                        return mi;
                }
 
@@ -7359,24 +7418,21 @@ namespace Mono.CSharp {
                {
                        Parameters parameters;
 
-                       public GetIndexerMethod (PropertyBase method):
+                       public GetIndexerMethod (Indexer method):
                                base (method)
                        {
+                               this.parameters = method.parameters;
                        }
 
                        public GetIndexerMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor)
                        {
+                               parameters = accessor.Parameters;
                        }
 
                        public override MethodBuilder Define (DeclSpace parent)
                        {
-                               //
-                               // Clone indexer accessor parameters for localized capturing
-                               //
-                               if (!IsDummy)
-                                       parameters = ((Indexer) method).parameters.Clone ();
-
+                               parameters.Resolve (ResolveContext);
                                return base.Define (parent);
                        }
                        
@@ -7399,22 +7455,18 @@ namespace Mono.CSharp {
 
                public class SetIndexerMethod: SetMethod
                {
-                       public SetIndexerMethod (PropertyBase method):
+                       public SetIndexerMethod (Indexer method):
                                base (method)
                        {
+                               parameters = Parameters.MergeGenerated (method.parameters, false, parameters [0], null);
                        }
 
                        public SetIndexerMethod (PropertyBase method, Accessor accessor):
                                base (method, accessor)
                        {
+                               parameters = method.Get.IsDummy ? accessor.Parameters : accessor.Parameters.Clone ();                   
                        }
 
-                       protected override void DefineParameters ()
-                       {
-                               parameters = Parameters.MergeGenerated (((Indexer)method).parameters,
-                                       new Parameter (method.MemberType, "value", Parameter.Modifier.NONE, null, method.Location));
-                       }
-                       
                        public override bool EnableOverloadChecks (MemberCore overload)
                        {
                                if (base.EnableOverloadChecks (overload)) {
@@ -7423,7 +7475,7 @@ namespace Mono.CSharp {
                                }
 
                                return false;
-                       }                       
+                       }
                }
 
                const int AllowedModifiers =
@@ -7529,7 +7581,7 @@ namespace Mono.CSharp {
                        // Now name the parameters
                        //
                        PropertyBuilder = Parent.TypeBuilder.DefineProperty (
-                               GetFullName (MemberName), PropertyAttributes.None, MemberType, parameters.Types);
+                               GetFullName (MemberName), PropertyAttributes.None, MemberType, parameters.GetEmitTypes ());
 
                        if (!Get.IsDummy) {
                                PropertyBuilder.SetGetMethod (GetBuilder);
@@ -7541,7 +7593,7 @@ namespace Mono.CSharp {
                                Parent.MemberCache.AddMember (SetBuilder, Set);
                        }
                                
-                       TypeManager.RegisterIndexer (PropertyBuilder, parameters.Types);
+                       TypeManager.RegisterIndexer (PropertyBuilder, parameters);
                        Parent.MemberCache.AddMember (PropertyBuilder, this);
                        return true;
                }
@@ -7577,7 +7629,7 @@ namespace Mono.CSharp {
                protected override PropertyInfo ResolveBaseProperty ()
                {
                        return Parent.PartialContainer.BaseCache.FindMemberToOverride (
-                               Parent.TypeBuilder, Name, parameters.Types, null, true) as PropertyInfo;
+                               Parent.TypeBuilder, Name, parameters, null, true) as PropertyInfo;
                }
 
                protected override bool VerifyClsCompliance ()
@@ -7711,11 +7763,6 @@ namespace Mono.CSharp {
                        else if (OperatorType == OpType.Implicit)
                                Parent.MemberCache.CheckExistingMembersOverloads (this, GetMetadataName (OpType.Explicit), Parameters);
 
-                       if (MemberType == TypeManager.void_type) {
-                               Report.Error (590, Location, "User-defined operators cannot return void");
-                               return false;
-                       }
-
                        Type declaring_type = MethodData.DeclaringType;
                        Type return_type = MemberType;
                        Type first_arg_type = ParameterTypes [0];
@@ -7774,7 +7821,7 @@ namespace Mono.CSharp {
                                        }
                                }
                        } else if (OperatorType == OpType.LeftShift || OperatorType == OpType.RightShift) {
-                               if (first_arg_type != declaring_type || ParameterTypes [1] != TypeManager.int32_type) {
+                               if (first_arg_type != declaring_type || Parameters.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;
                                }
@@ -7814,7 +7861,7 @@ namespace Mono.CSharp {
                                // Checks for Binary operators
                                
                                if (first_arg_type != declaring_type &&
-                                   ParameterTypes [1] != declaring_type){
+                                   Parameters.Types [1] != declaring_type){
                                        Report.Error (
                                                563, Location,
                                                "One of the parameters of a binary operator must " +
@@ -7899,24 +7946,24 @@ namespace Mono.CSharp {
                public OpType GetMatchingOperator ()
                {
                        switch (OperatorType) {
-                               case OpType.Equality:
-                                       return OpType.Inequality;
-                               case OpType.Inequality:
-                                       return OpType.Equality;
-                               case OpType.True:
-                                       return OpType.False;
-                               case OpType.False:
-                                       return OpType.True;
-                               case OpType.GreaterThan:
-                                       return OpType.LessThan;
-                               case OpType.LessThan:
-                                       return OpType.GreaterThan;
-                               case OpType.GreaterThanOrEqual:
-                                       return OpType.LessThanOrEqual;
-                               case OpType.LessThanOrEqual:
-                                       return OpType.GreaterThanOrEqual;
-                               default:
-                                       return OpType.TOP;
+                       case OpType.Equality:
+                               return OpType.Inequality;
+                       case OpType.Inequality:
+                               return OpType.Equality;
+                       case OpType.True:
+                               return OpType.False;
+                       case OpType.False:
+                               return OpType.True;
+                       case OpType.GreaterThan:
+                               return OpType.LessThan;
+                       case OpType.LessThan:
+                               return OpType.GreaterThan;
+                       case OpType.GreaterThanOrEqual:
+                               return OpType.LessThanOrEqual;
+                       case OpType.LessThanOrEqual:
+                               return OpType.GreaterThanOrEqual;
+                       default:
+                               return OpType.TOP;
                        }
                }
 
@@ -8043,7 +8090,7 @@ namespace Mono.CSharp {
                        if (mi != null)
                                args = TypeManager.GetParameterData (mi).Types;
                        else
-                               args = TypeManager.GetArgumentTypes (pi);
+                               args = TypeManager.GetParameterData (pi).Types;
                        Type [] sigp = sig.Parameters;
 
                        if (args.Length != sigp.Length)