[mcs] When setting struct empty layout consider compiler generated fields. Fixes...
[mono.git] / mcs / mcs / property.cs
index 1d46ab2dab8b87ed13f9e871bd5459a3ee07f6a4..5d831e940b523b144287c7e0d47f0394e3677147 100644 (file)
@@ -17,7 +17,7 @@ using System.Collections.Generic;
 using System.Text;
 using Mono.CompilerServices.SymbolWriter;
 
-#if NET_2_1
+#if MOBILE
 using XmlElement = System.Object;
 #endif
 
@@ -82,8 +82,6 @@ namespace Mono.CSharp
                        }
                }
 
-               public abstract void PrepareEmit ();
-
                protected override bool VerifyClsCompliance ()
                {
                        if (!base.VerifyClsCompliance ())
@@ -246,7 +244,7 @@ namespace Mono.CSharp
                        protected override void ApplyToExtraTarget (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
                        {
                                if (a.Target == AttributeTargets.Parameter) {
-                                       parameters[0].ApplyAttributeBuilder (a, ctor, cdata, pa);
+                                       parameters[parameters.Count - 1].ApplyAttributeBuilder (a, ctor, cdata, pa);
                                        return;
                                }
 
@@ -548,19 +546,21 @@ namespace Mono.CSharp
                        }
 
                        if (Set == null) {
-                               if ((ModFlags & Modifiers.SEALED) != 0 && base_prop.HasSet && !base_prop.Set.IsAccessible (this)) {
-                                       // TODO: Should be different error code but csc uses for some reason same
-                                       Report.SymbolRelatedToPreviousError (base_prop);
-                                       Report.Error (546, Location,
-                                               "`{0}': cannot override because `{1}' does not have accessible set accessor",
-                                               GetSignatureForError (), base_prop.GetSignatureForError ());
-                                       ok = false;
-                               }
+                               if (base_prop.HasSet) {
+                                       if ((ModFlags & Modifiers.SEALED) != 0 && !base_prop.Set.IsAccessible (this)) {
+                                               // TODO: Should be different error code but csc uses for some reason same
+                                               Report.SymbolRelatedToPreviousError (base_prop);
+                                               Report.Error (546, Location,
+                                                       "`{0}': cannot override because `{1}' does not have accessible set accessor",
+                                                       GetSignatureForError (), base_prop.GetSignatureForError ());
+                                               ok = false;
+                                       }
 
-                               if ((ModFlags & Modifiers.AutoProperty) != 0) {
-                                       Report.Error (8080, Location, "`{0}': Auto-implemented properties must override all accessors of the overridden property",
-                                               GetSignatureForError ());
-                                       ok = false;
+                                       if ((ModFlags & Modifiers.AutoProperty) != 0) {
+                                               Report.Error (8080, Location, "`{0}': Auto-implemented properties must override all accessors of the overridden property",
+                                                       GetSignatureForError ());
+                                               ok = false;
+                                       }
                                }
                        } else {
                                if (!base_prop.HasSet) {
@@ -617,8 +617,7 @@ namespace Mono.CSharp
                                                GetSignatureForError ());
                                }
                        } else if ((ModFlags & Modifiers.OVERRIDE) == 0 && 
-                               (Get == null && (Set.ModFlags & Modifiers.AccessibilityMask) != 0) ||
-                               (Set == null && (Get.ModFlags & Modifiers.AccessibilityMask) != 0)) {
+                               ((Get == null && (Set.ModFlags & Modifiers.AccessibilityMask) != 0) || (Set == null && (Get.ModFlags & Modifiers.AccessibilityMask) != 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 ());
@@ -821,8 +820,10 @@ namespace Mono.CSharp
                        Parent.PartialContainer.Members.Add (BackingField);
 
                        FieldExpr fe = new FieldExpr (BackingField, Location);
-                       if ((BackingField.ModFlags & Modifiers.STATIC) == 0)
+                       if ((BackingField.ModFlags & Modifiers.STATIC) == 0) {
                                fe.InstanceExpression = new CompilerGeneratedThis (Parent.CurrentType, Location);
+                               Parent.PartialContainer.HasInstanceField = true;
+                       }
 
                        //
                        // Create get block but we careful with location to
@@ -902,7 +903,7 @@ namespace Mono.CSharp
 
                public override void Emit ()
                {
-                       if ((AccessorFirst.ModFlags & (Modifiers.STATIC | Modifiers.COMPILER_GENERATED)) == Modifiers.COMPILER_GENERATED && Parent.PartialContainer.HasExplicitLayout) {
+                       if ((AccessorFirst.ModFlags & (Modifiers.STATIC | Modifiers.AutoProperty)) == Modifiers.AutoProperty && Parent.PartialContainer.HasExplicitLayout) {
                                Report.Error (842, Location,
                                        "Automatically implemented property `{0}' cannot be used inside a type with an explicit StructLayout attribute",
                                        GetSignatureForError ());
@@ -1211,12 +1212,11 @@ namespace Mono.CSharp
 
                        backing_field = new Field (Parent,
                                new TypeExpression (MemberType, Location),
-                               Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
+                               Modifiers.BACKING_FIELD | Modifiers.COMPILER_GENERATED | Modifiers.DEBUGGER_HIDDEN | Modifiers.PRIVATE | (ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE)),
                                MemberName, null);
 
                        Parent.PartialContainer.Members.Add (backing_field);
                        backing_field.Initializer = Initializer;
-                       backing_field.ModFlags &= ~Modifiers.COMPILER_GENERATED;
 
                        // Call define because we passed fields definition
                        backing_field.Define ();
@@ -1450,6 +1450,8 @@ namespace Mono.CSharp
 
                public override void PrepareEmit ()
                {
+                       base.PrepareEmit ();
+
                        add.PrepareEmit ();
                        remove.PrepareEmit ();
 
@@ -1759,9 +1761,8 @@ namespace Mono.CSharp
 
                public override void PrepareEmit ()
                {
-                       parameters.ResolveDefaultValues (this);
-
                        base.PrepareEmit ();
+                       parameters.ResolveDefaultValues (this);
                }
 
                protected override bool VerifyClsCompliance ()