From ec1fbec7c119e1c438c386df722e281586636e7a Mon Sep 17 00:00:00 2001 From: Marek Safar Date: Tue, 12 Apr 2011 13:49:02 +0100 Subject: [PATCH] Check allowed modifiers on property accessors --- mcs/errors/cs0106-9.cs | 9 +++++++++ mcs/mcs/class.cs | 2 +- mcs/mcs/property.cs | 8 ++++---- 3 files changed, 14 insertions(+), 5 deletions(-) create mode 100644 mcs/errors/cs0106-9.cs diff --git a/mcs/errors/cs0106-9.cs b/mcs/errors/cs0106-9.cs new file mode 100644 index 00000000000..ba6621b3715 --- /dev/null +++ b/mcs/errors/cs0106-9.cs @@ -0,0 +1,9 @@ +// CS0106: The modifier `virtual' is not valid for this item +// Line: 7 + +class C +{ + public int Foo { + virtual set { } + } +} diff --git a/mcs/mcs/class.cs b/mcs/mcs/class.cs index 8951ac1728d..1a4ec83b2cd 100644 --- a/mcs/mcs/class.cs +++ b/mcs/mcs/class.cs @@ -2875,7 +2875,7 @@ namespace Mono.CSharp /// /// Modifiers allowed in a class declaration /// - public const Modifiers AllowedModifiers = + const Modifiers AllowedModifiers = Modifiers.NEW | Modifiers.PUBLIC | Modifiers.PROTECTED | diff --git a/mcs/mcs/property.cs b/mcs/mcs/property.cs index c5fea5c1110..641177464e1 100644 --- a/mcs/mcs/property.cs +++ b/mcs/mcs/property.cs @@ -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 ()); } -- 2.25.1