+2004-12-13 Marek Safar <marek.safar@seznam.cz>
+
+ * class.cs (TypeContainer.VerifyClsCompliance): Add error
+ 3018 report.
+ (PropertyBase.VerifyClsCompliance): Add errror 3025 report.
+
+ * codegen.cs (ModuleClass.ApplyAttributeBuilder): Add error
+ 3017 report.
+
+ * decl.cs (MemberCore.VerifyClsCompliance): Add warning 3021.
+
+ * parameter.cs (ReturnParameter.ApplyAttributeBuilder):
+ Add error 3023 report.
+ (Parameter.ApplyAttributeBuilder): Add error 3022 report.
+
+ * tree.cs (RootTypes.IsClsCompliaceRequired): Add fake
+ implementation.
+
2004-12-12 John Luke <john.luke@gmail.com>
* driver.cs (AddArgs): take -- into account when
if (base_type != null && !AttributeTester.IsClsCompliant (base_type)) {
Report.Error (3009, Location, "'{0}': base type '{1}' is not CLS-compliant", GetSignatureForError (), TypeManager.CSharpName (base_type));
}
+
+ if (!Parent.IsClsCompliaceRequired (ds)) {
+ Report.Error (3018, Location, "'{0}' cannot be marked as CLS-Compliant because it is a member of non CLS-Compliant type '{1}'",
+ GetSignatureForError (), Parent.GetSignatureForError ());
+ }
return true;
}
//
// Check for custom access modifier
//
- if (ModFlags == 0) {
- ModFlags = method.ModFlags;
- flags = method.flags;
- } else {
+ if (ModFlags == 0) {
+ ModFlags = method.ModFlags;
+ flags = method.flags;
+ } else {
CheckModifiers (container, ModFlags);
ModFlags |= (method.ModFlags & (~Modifiers.Accessibility));
flags = Modifiers.MethodAttr (ModFlags);
}
void CheckModifiers (TypeContainer container, int modflags)
- {
- int flags = 0;
- int mflags = method.ModFlags & Modifiers.Accessibility;
-
- if ((mflags & Modifiers.PUBLIC) != 0) {
- flags |= Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE;
- }
- else if ((mflags & Modifiers.PROTECTED) != 0) {
- if ((mflags & Modifiers.INTERNAL) != 0)
- flags |= Modifiers.PROTECTED | Modifiers.INTERNAL;
+ {
+ int flags = 0;
+ int mflags = method.ModFlags & Modifiers.Accessibility;
- flags |= Modifiers.PRIVATE;
- }
- else if ((mflags & Modifiers.INTERNAL) != 0)
- flags |= Modifiers.PRIVATE;
+ if ((mflags & Modifiers.PUBLIC) != 0) {
+ flags |= Modifiers.PROTECTED | Modifiers.INTERNAL | Modifiers.PRIVATE;
+ }
+ else if ((mflags & Modifiers.PROTECTED) != 0) {
+ if ((mflags & Modifiers.INTERNAL) != 0)
+ flags |= Modifiers.PROTECTED | Modifiers.INTERNAL;
- if ((mflags == modflags) || (modflags & (~flags)) != 0)
- Report.Error (273, Location, "{0}: accessibility modifier must be more restrictive than the property or indexer",
- GetSignatureForError (container));
- }
+ flags |= Modifiers.PRIVATE;
+ }
+ else if ((mflags & Modifiers.INTERNAL) != 0)
+ flags |= Modifiers.PRIVATE;
+ if ((mflags == modflags) || (modflags & (~flags)) != 0)
+ Report.Error (273, Location, "{0}: accessibility modifier must be more restrictive than the property or indexer",
+ GetSignatureForError (container));
+ }
}
Set.UpdateName (this);
}
+ protected override bool VerifyClsCompliance (DeclSpace ds)
+ {
+ if (!base.VerifyClsCompliance (ds))
+ return false;
+
+ if ((Get.ModFlags != ModFlags && !Get.IsDummy) || (Set.ModFlags != ModFlags && !Set.IsDummy)) {
+ Report.Error (3025, Get.ModFlags != ModFlags ? Get.Location : Set.Location,
+ "CLS-compliant accessors must have the same accessibility as their property");
+ }
+ return true;
+ }
public override string[] ValidAttributeTargets {
get {
// TODO: make it private and move all builder based methods here
public AssemblyBuilder Builder;
bool is_cls_compliant;
+ public Attribute ClsCompliantAttribute;
ListDictionary declarative_security;
public void ResolveClsCompliance ()
{
- Attribute a = GetClsCompliantAttribute ();
- if (a == null)
+ ClsCompliantAttribute = GetClsCompliantAttribute ();
+ if (ClsCompliantAttribute == null)
return;
- is_cls_compliant = a.GetClsCompliantAttributeValue (null);
+ is_cls_compliant = ClsCompliantAttribute.GetClsCompliantAttributeValue (null);
}
// fix bug #56621
return;
}
- ApplyAttributeBuilder (null, new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
+ Builder.SetCustomAttribute (new CustomAttributeBuilder (TypeManager.unverifiable_code_ctor, new object [0]));
}
public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder customBuilder)
{
- if (a != null && a.Type == TypeManager.cls_compliant_attribute_type) {
- Report.Warning (3012, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+ if (a.Type == TypeManager.cls_compliant_attribute_type) {
+ if (CodeGen.Assembly.ClsCompliantAttribute == null) {
+ Report.Warning (3012, a.Location, "You must specify the CLSCompliant attribute on the assembly, not the module, to enable CLS compliance checking");
+ }
+ else if (CodeGen.Assembly.IsClsCompliant != a.GetBoolean ()) {
+ Report.SymbolRelatedToPreviousError (CodeGen.Assembly.ClsCompliantAttribute.Location, CodeGen.Assembly.ClsCompliantAttribute.Name);
+ Report.Error (3017, a.Location, "You cannot specify the CLSCompliant attribute on a module that differs from the CLSCompliant attribute on the assembly");
+ return;
+ }
}
Builder.SetCustomAttribute (customBuilder);
protected virtual bool VerifyClsCompliance (DeclSpace ds)
{
if (!IsClsCompliaceRequired (ds)) {
- if ((RootContext.WarningLevel >= 2) && HasClsCompliantAttribute && !IsExposedFromAssembly (ds)) {
- Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
+ if (HasClsCompliantAttribute && RootContext.WarningLevel >= 2) {
+ if (!IsExposedFromAssembly (ds))
+ Report.Warning (3019, Location, "CLS compliance checking will not be performed on '{0}' because it is private or internal", GetSignatureForError ());
+ if (!CodeGen.Assembly.IsClsCompliant)
+ Report.Warning (3021, Location, "'{0}' does not need a CLSCompliant attribute because the assembly does not have a CLSCompliant attribute", GetSignatureForError ());
}
return false;
}
public override void ApplyAttributeBuilder(Attribute a, CustomAttributeBuilder cb)
{
+ if (a.Type == TypeManager.cls_compliant_attribute_type) {
+ Report.Warning (3023, 1, a.Location, "CLSCompliant attribute has no meaning when applied to return types. Try putting it on the method instead");
+ }
+
// This occurs after Warning -28
if (builder == null)
return;
Report.Error (674, a.Location, "Do not use 'System.ParamArrayAttribute'. Use the 'params' keyword instead");
return;
}
+
+ if (a.Type == TypeManager.cls_compliant_attribute_type) {
+ Report.Warning (3022, 1, a.Location, "CLSCompliant attribute has no meaning when applied to parameters. Try putting it on the method instead");
+ }
+
base.ApplyAttributeBuilder (a, cb);
}
{
throw new InvalidOperationException ();
}
+
+ public override bool IsClsCompliaceRequired (DeclSpace ds)
+ {
+ return true;
+ }
+
}
}