Check allowed modifiers on property accessors
authorMarek Safar <marek.safar@gmail.com>
Tue, 12 Apr 2011 12:49:02 +0000 (13:49 +0100)
committerMarek Safar <marek.safar@gmail.com>
Tue, 12 Apr 2011 14:15:45 +0000 (15:15 +0100)
mcs/errors/cs0106-9.cs [new file with mode: 0644]
mcs/mcs/class.cs
mcs/mcs/property.cs

diff --git a/mcs/errors/cs0106-9.cs b/mcs/errors/cs0106-9.cs
new file mode 100644 (file)
index 0000000..ba6621b
--- /dev/null
@@ -0,0 +1,9 @@
+// CS0106: The modifier `virtual' is not valid for this item
+// Line: 7
+
+class C
+{
+       public int Foo {
+               virtual set { }
+       }
+}
index 8951ac1728d3f93850b8224b5dbea75aed009bce..1a4ec83b2cd1efaf47fff920f27f21f424eb2056 100644 (file)
@@ -2875,7 +2875,7 @@ namespace Mono.CSharp
                /// <summary>
                ///   Modifiers allowed in a class declaration
                /// </summary>
-               public const Modifiers AllowedModifiers =
+               const Modifiers AllowedModifiers =
                        Modifiers.NEW       |
                        Modifiers.PUBLIC    |
                        Modifiers.PROTECTED |
index c5fea5c11104d5493489fc5b83c21d71eb53df98..641177464e194eb391967e17f848ff3528d8673e 100644 (file)
@@ -306,7 +306,7 @@ namespace Mono.CSharp
 
                public abstract class PropertyMethod : AbstractPropertyEventMethod
                {
-                       public const Modifiers AllowedModifiers =
+                       const Modifiers AllowedModifiers =
                                Modifiers.PUBLIC |
                                Modifiers.PROTECTED |
                                Modifiers.INTERNAL |
@@ -319,7 +319,8 @@ namespace Mono.CSharp
                                : base (method, prefix, attrs, loc)
                        {
                                this.method = method;
-                               this.ModFlags = modifiers | (method.ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE));
+                               this.ModFlags = ModifiersExtensions.Check (AllowedModifiers, modifiers, 0, loc, Report);
+                               this.ModFlags |= (method.ModFlags & (Modifiers.STATIC | Modifiers.UNSAFE));
                        }
 
                        public override void ApplyAttributeBuilder (Attribute a, MethodSpec ctor, byte[] cdata, PredefinedAttributes pa)
@@ -356,8 +357,7 @@ namespace Mono.CSharp
                                        if (container.Kind == MemberKind.Interface)
                                                Report.Error (275, Location, "`{0}': accessibility modifiers may not be used on accessors in an interface",
                                                        GetSignatureForError ());
-
-                                       if ((method.ModFlags & Modifiers.ABSTRACT) != 0 && (ModFlags & Modifiers.PRIVATE) != 0) {
+                                       else if ((method.ModFlags & Modifiers.ABSTRACT) != 0 && (ModFlags & Modifiers.PRIVATE) != 0) {
                                                Report.Error (442, Location, "`{0}': abstract properties cannot have private accessors", GetSignatureForError ());
                                        }