[mcs] If the overriding property is sealed, then the overridden accessors cannot...
authorMarek Safar <marek.safar@gmail.com>
Thu, 29 May 2014 12:32:27 +0000 (14:32 +0200)
committerMarek Safar <marek.safar@gmail.com>
Thu, 29 May 2014 12:32:27 +0000 (14:32 +0200)
mcs/errors/cs0545-2.cs [new file with mode: 0644]
mcs/errors/cs0546-2.cs [new file with mode: 0644]
mcs/mcs/property.cs

diff --git a/mcs/errors/cs0545-2.cs b/mcs/errors/cs0545-2.cs
new file mode 100644 (file)
index 0000000..61d3887
--- /dev/null
@@ -0,0 +1,16 @@
+// CS0545: `B.Prop': cannot override because `A.Prop' does not have accessible get accessor
+// Line: 13
+
+public class A
+{
+       public virtual string Prop {
+               set; private get;
+       }  
+}
+public class B : A
+{
+       sealed override public string Prop {
+               set { }
+       }   
+}
\ No newline at end of file
diff --git a/mcs/errors/cs0546-2.cs b/mcs/errors/cs0546-2.cs
new file mode 100644 (file)
index 0000000..4cec448
--- /dev/null
@@ -0,0 +1,16 @@
+// CS0546: `B.Prop': cannot override because `A.Prop' does not have accessible set accessor
+// Line: 13
+
+public class A
+{
+       public virtual string Prop {
+               get; private set;
+       }
+}
+public class B : A
+{
+       sealed override public string Prop {
+               get { return ""; }
+       }
+}
\ No newline at end of file
index 339d42d8f6753c1fad8a13f00ee0a4f5f1935a5d..e8b3879f05afb10598cf8d54e3f1d093015910c2 100644 (file)
@@ -512,7 +512,16 @@ namespace Mono.CSharp
                        // Check base property accessors conflict
                        //
                        var base_prop = (PropertySpec) base_member;
-                       if (Get != null) {
+                       if (Get == null) {
+                               if ((ModFlags & Modifiers.SEALED) != 0 && base_prop.HasGet && !base_prop.Get.IsAccessible (this)) {
+                                       // TODO: Should be different error code but csc uses for some reason same
+                                       Report.SymbolRelatedToPreviousError (base_prop);
+                                       Report.Error (545, Location,
+                                               "`{0}': cannot override because `{1}' does not have accessible get accessor",
+                                               GetSignatureForError (), base_prop.GetSignatureForError ());
+                                       ok = false;
+                               }
+                       } else {
                                if (!base_prop.HasGet) {
                                        if (ok) {
                                                Report.SymbolRelatedToPreviousError (base_prop);
@@ -529,7 +538,16 @@ namespace Mono.CSharp
                                }
                        }
 
-                       if (Set != null) {
+                       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;
+                               }
+                       } else {
                                if (!base_prop.HasSet) {
                                        if (ok) {
                                                Report.SymbolRelatedToPreviousError (base_prop);