[mcs] When setting struct empty layout consider compiler generated fields. Fixes...
[mono.git] / mcs / mcs / property.cs
index 4b7b21e4887bfb9c5627b494cfbb489e03dededd..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 ())
@@ -619,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 ());
@@ -823,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
@@ -904,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 ());
@@ -1213,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 ();
@@ -1452,6 +1450,8 @@ namespace Mono.CSharp
 
                public override void PrepareEmit ()
                {
+                       base.PrepareEmit ();
+
                        add.PrepareEmit ();
                        remove.PrepareEmit ();
 
@@ -1761,9 +1761,8 @@ namespace Mono.CSharp
 
                public override void PrepareEmit ()
                {
-                       parameters.ResolveDefaultValues (this);
-
                        base.PrepareEmit ();
+                       parameters.ResolveDefaultValues (this);
                }
 
                protected override bool VerifyClsCompliance ()