[mcs] Implements C# 7.2 readonly structs
[mono.git] / mcs / mcs / property.cs
index 3478711470a0fa6d93b668621c5d60392e2fda08..c55432cf2d59171c7b4a9e3576a418ec8b12c300 100644 (file)
@@ -880,10 +880,16 @@ namespace Mono.CSharp
                                }
 
                                if (MemberType.Kind == MemberKind.ByRef) {
-                                       Report.Error (8145, Location, "Auto-implemented properties cannot return by reference");
+                                       Report.Error (8145, Location, "Auto-implemented property `{0}' cannot return by reference",
+                                               GetSignatureForError ());
                                        return false;
                                }
 
+                               if ((Parent.PartialContainer.ModFlags & Modifiers.READONLY) != 0 && Set != null && !IsStatic) {
+                                       Report.Error (8341, Location, "Auto-implemented instance property `{0}' in readonly structs must be readonly",
+                                               GetSignatureForError ());
+                               }
+
                                if (Compiler.Settings.Version < LanguageVersion.V_3 && Initializer == null)
                                        Report.FeatureIsNotAvailable (Compiler, Location, "auto-implemented properties");
 
@@ -1191,6 +1197,16 @@ namespace Mono.CSharp
                        base.ApplyAttributeBuilder (a, ctor, cdata, pa);
                }
 
+               protected override void DoMemberTypeIndependentChecks ()
+               {
+                       if ((Parent.PartialContainer.ModFlags & Modifiers.READONLY) != 0 && (ModFlags & Modifiers.STATIC) == 0) {
+                               Report.Error (8342, Location, "`{0}': Field-like instance events are not allowed in readonly structs",
+                                       GetSignatureForError ());
+                       }
+
+                       base.DoMemberTypeIndependentChecks ();
+               }
+
                public override bool Define()
                {
                        var mod_flags_src = ModFlags;