2007-12-06 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / mcs / class.cs
index 67b1ba5e44ca193f33dbee84794182fddc3b6c7c..9a6689ea67a82d5ce96082159ae2106e61968d9f 100644 (file)
@@ -3706,23 +3706,20 @@ namespace Mono.CSharp {
                        if ((base_classp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
                                //
                                // when overriding protected internal, the method can be declared
-                               // protected internal only within the same assembly
+                               // protected internal only within the same assembly or assembly
+                               // which has InternalsVisibleTo
                                //
-
                                if ((thisp & MethodAttributes.FamORAssem) == MethodAttributes.FamORAssem){
-                                       if (Parent.TypeBuilder.Assembly != base_method.DeclaringType.Assembly){
-                                               //
-                                               // assemblies differ - report an error
-                                               //
-                                               
-                                               return false;
-                                       } else if (thisp != base_classp) {
+                                       if (Parent.TypeBuilder.Assembly != base_method.DeclaringType.Assembly)
+                                               return TypeManager.IsFriendAssembly (base_method.DeclaringType.Assembly);
+
+                                       if (thisp != base_classp) {
                                                //
                                                // same assembly, but other attributes differ - report an error
                                                //
                                                
                                                return false;
-                                       };
+                                       }
                                } else if ((thisp & MethodAttributes.Family) != MethodAttributes.Family) {
                                        //
                                        // if it's not "protected internal", it must be "protected"
@@ -6083,15 +6080,6 @@ namespace Mono.CSharp {
 
                        FieldAttributes fa = Modifiers.FieldAttr (ModFlags);
 
-                       if (Parent.PartialContainer.Kind == Kind.Struct && 
-                           ((fa & FieldAttributes.Static) == 0) &&
-                           MemberType == Parent.TypeBuilder &&
-                           !TypeManager.IsBuiltinType (MemberType)){
-                               Report.Error (523, Location, "Struct member `" + Parent.Name + "." + Name + 
-                                             "' causes a cycle in the structure layout");
-                               return false;
-                       }
-
                        try {
                                FieldBuilder = Parent.TypeBuilder.DefineField (
                                        Name, MemberType, Modifiers.FieldAttr (ModFlags));
@@ -6107,6 +6095,14 @@ namespace Mono.CSharp {
                        if (initializer != null)
                                ((TypeContainer) Parent).RegisterFieldForInitialization (this,
                                        new FieldInitializer (FieldBuilder, initializer));
+
+                       if (Parent.PartialContainer.Kind == Kind.Struct && (fa & FieldAttributes.Static) == 0 &&
+                               MemberType == Parent.TypeBuilder && !TypeManager.IsBuiltinType (MemberType) && initializer == null) {
+                               Report.Error (523, Location, "Struct member `{0}' causes a cycle in the structure layout",
+                                       GetSignatureForError ());
+                               return false;
+                       }
+
                        return true;
                }
 
@@ -6916,7 +6912,7 @@ namespace Mono.CSharp {
                        Modifiers.SEALED |
                        Modifiers.OVERRIDE |
                        Modifiers.ABSTRACT |
-                       Modifiers.UNSAFE |
+                       Modifiers.UNSAFE |
                        Modifiers.EXTERN |
                        Modifiers.METHOD_YIELDS |
                        Modifiers.VIRTUAL;
@@ -6930,8 +6926,7 @@ namespace Mono.CSharp {
                        Field field = new Field (
                                Parent, Type,
                                Modifiers.COMPILER_GENERATED | Modifiers.PRIVATE | (ModFlags & Modifiers.STATIC),
-                               CompilerGeneratedClass.MakeName (null, "CompilerGeneratedField"),
-                               null, Location);
+                           "<" + Name + ">k__BackingField", null, Location);
                        ((TypeContainer)Parent).AddField (field);
 
                        // Make get block
@@ -6963,12 +6958,14 @@ namespace Mono.CSharp {
                                is_iface ? AllowedInterfaceModifiers : AllowedModifiers,
                                is_iface, name, attrs, define_set_first)
                {
-                       if (RootContext.Version >= LanguageVersion.LINQ &&
-                               !is_iface &&
-                               (mod & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 &&
+                       if (!is_iface && (mod & (Modifiers.ABSTRACT | Modifiers.EXTERN)) == 0 &&
                                get_block != null && get_block.Block == null &&
-                               set_block != null && set_block.Block == null)
+                               set_block != null && set_block.Block == null) {
+                               if (RootContext.Version <= LanguageVersion.ISO_2)
+                                       Report.FeatureIsNotAvailable (Location, "automatically implemented properties");
+                               
                                CreateAutomaticProperty (current_block, get_block, set_block);
+                       }
 
                        if (get_block == null)
                                Get = new GetMethod (this);
@@ -7387,6 +7384,9 @@ namespace Mono.CSharp {
                        if (TypeManager.IsGenericType (MemberType))
                                SetMemberIsUsed();
 
+                       if (Add.IsInterfaceImplementation)
+                               SetMemberIsUsed ();
+
                        FieldBuilder = Parent.TypeBuilder.DefineField (
                                Name, MemberType,
                                FieldAttributes.Private | ((ModFlags & Modifiers.STATIC) != 0 ? FieldAttributes.Static : 0));
@@ -7440,6 +7440,10 @@ namespace Mono.CSharp {
                                get { return null; }
                        }
 
+                       public bool IsInterfaceImplementation {
+                               get { return method_data.implementing != null; }
+                       }
+
                        public override void ApplyAttributeBuilder (Attribute a, CustomAttributeBuilder cb)
                        {
                                if (a.IsInternalMethodImplAttribute) {
@@ -7823,15 +7827,6 @@ namespace Mono.CSharp {
                        //
                        // Now name the parameters
                        //
-                       Parameter [] p = parameters.FixedParameters;
-                       if (p != null) {
-                               // TODO: should be done in parser and it needs to do cycle
-                               if ((p [0].ModFlags & Parameter.Modifier.ISBYREF) != 0) {
-                                       CSharpParser.Error_ParameterModifierNotValid (Location);
-                                       return false;
-                               }
-                       }
-
                        PropertyBuilder = Parent.TypeBuilder.DefineProperty (
                                Name, PropertyAttributes.None, MemberType, parameters.Types);