Null constant cannot be used for ref/out variables
[mono.git] / mcs / mcs / decl.cs
index cba83b950b9d5e66604335b5a4cd69ee7f06458e..6cebf38c3b905c358d41d73e13080445cb40ae5a 100644 (file)
@@ -31,7 +31,7 @@ namespace Mono.CSharp {
        //
        public class MemberName {
                public readonly string Name;
-               public readonly TypeArguments TypeArguments;
+               public TypeArguments TypeArguments;
 
                public readonly MemberName Left;
                public readonly Location Location;
@@ -384,7 +384,7 @@ namespace Mono.CSharp {
                                                if (pm is Indexer.GetIndexerMethod || pm is Indexer.SetIndexerMethod)
                                                        pm = null;
 
-                                               if (pm != null && (pm.Property.Get.IsDummy || pm.Property.Set.IsDummy)) {
+                                               if (pm != null && pm.Property.AccessorSecond == null) {
                                                        Report.Error (840, Location,
                                                                "`{0}' must have a body because it is not marked abstract or extern. The property can be automatically implemented when you define both accessors",
                                                                GetSignatureForError ());
@@ -475,7 +475,9 @@ namespace Mono.CSharp {
                }
 
                public virtual bool IsUsed {
-                       get { return (caching_flags & Flags.IsUsed) != 0; }
+                       get {
+                               return (caching_flags & Flags.IsUsed) != 0;
+                       }
                }
 
                protected Report Report {
@@ -507,7 +509,7 @@ namespace Mono.CSharp {
                        if (OptAttributes == null)
                                return null;
 
-                       Attribute obsolete_attr = OptAttributes.Search (PredefinedAttributes.Get.Obsolete);
+                       Attribute obsolete_attr = OptAttributes.Search (Compiler.PredefinedAttributes.Obsolete);
                        if (obsolete_attr == null)
                                return null;
 
@@ -596,11 +598,12 @@ namespace Mono.CSharp {
                                        case Modifiers.PROTECTED | Modifiers.INTERNAL:
                                                if (al == Modifiers.INTERNAL)
                                                        same_access_restrictions = TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
-                                               else if (al == Modifiers.PROTECTED)
-                                                       same_access_restrictions = mc.Parent.IsBaseTypeDefinition (p_parent);
                                                else if (al == (Modifiers.PROTECTED | Modifiers.INTERNAL))
                                                        same_access_restrictions = mc.Parent.IsBaseTypeDefinition (p_parent) &&
                                                                TypeManager.IsThisOrFriendAssembly (Parent.Module.Assembly, p.Assembly);
+                                               else
+                                                       goto case Modifiers.PROTECTED;
+
                                                break;
 
                                        case Modifiers.PRIVATE:
@@ -676,9 +679,9 @@ namespace Mono.CSharp {
                        return true;
                }
 
-               public virtual ExtensionMethodGroupExpr LookupExtensionMethod (TypeSpec extensionType, string name, int arity, Location loc)
+               public virtual IList<MethodSpec> LookupExtensionMethod (TypeSpec extensionType, string name, int arity, ref NamespaceEntry scope)
                {
-                       return Parent.LookupExtensionMethod (extensionType, name, arity, loc);
+                       return Parent.LookupExtensionMethod (extensionType, name, arity, ref scope);
                }
 
                public virtual FullNamedExpression LookupNamespaceAlias (string name)
@@ -703,7 +706,7 @@ namespace Mono.CSharp {
                        caching_flags &= ~Flags.HasCompliantAttribute_Undetected;
 
                        if (OptAttributes != null) {
-                               Attribute cls_attribute = OptAttributes.Search (PredefinedAttributes.Get.CLSCompliant);
+                               Attribute cls_attribute = OptAttributes.Search (Compiler.PredefinedAttributes.CLSCompliant);
                                if (cls_attribute != null) {
                                        caching_flags |= Flags.HasClsCompliantAttribute;
                                        if (cls_attribute.GetClsCompliantAttributeValue ())
@@ -747,7 +750,7 @@ namespace Mono.CSharp {
                {
                        if (HasClsCompliantAttribute) {
                                if (CodeGen.Assembly.ClsCompliantAttribute == null) {
-                                       Attribute a = OptAttributes.Search (PredefinedAttributes.Get.CLSCompliant);
+                                       Attribute a = OptAttributes.Search (Compiler.PredefinedAttributes.CLSCompliant);
                                        if ((caching_flags & Flags.ClsCompliantAttributeFalse) != 0) {
                                                Report.Warning (3021, 2, a.Location,
                                                        "`{0}' does not need a CLSCompliant attribute because the assembly is not marked as CLS-compliant",
@@ -761,7 +764,7 @@ namespace Mono.CSharp {
                                }
 
                                if (!IsExposedFromAssembly ()) {
-                                       Attribute a = OptAttributes.Search (PredefinedAttributes.Get.CLSCompliant);
+                                       Attribute a = OptAttributes.Search (Compiler.PredefinedAttributes.CLSCompliant);
                                        Report.Warning (3019, 2, a.Location, "CLS compliance checking will not be performed on `{0}' because it is not visible from outside this assembly", GetSignatureForError ());
                                        return false;
                                }
@@ -777,7 +780,7 @@ namespace Mono.CSharp {
                                }
 
                                if (Parent.Parent != null && !Parent.IsClsComplianceRequired ()) {
-                                       Attribute a = OptAttributes.Search (PredefinedAttributes.Get.CLSCompliant);
+                                       Attribute a = OptAttributes.Search (Compiler.PredefinedAttributes.CLSCompliant);
                                        Report.Warning (3018, 1, a.Location, "`{0}' cannot be marked as CLS-compliant because it is a member of non CLS-compliant type `{1}'",
                                                GetSignatureForError (), Parent.GetSignatureForError ());
                                        return false;
@@ -984,8 +987,7 @@ namespace Mono.CSharp {
 
                //
                // Return true when this member is a generic in C# terms
-               // therefore nested non-generic type of generic type will
-               // return false
+               // A nested non-generic type of generic type will return false
                //
                public bool IsGeneric {
                        get {
@@ -1000,6 +1002,10 @@ namespace Mono.CSharp {
                        get { return (modifiers & Modifiers.PRIVATE) != 0; }
                }
 
+               public bool IsPublic {
+                       get { return (modifiers & Modifiers.PUBLIC) != 0; }
+               }
+
                public bool IsStatic {
                        get { 
                                return (modifiers & Modifiers.STATIC) != 0;
@@ -1039,9 +1045,45 @@ namespace Mono.CSharp {
                        var inflated = (MemberSpec) MemberwiseClone ();
                        inflated.declaringType = inflator.TypeInstance;
                        inflated.state |= StateFlags.PendingMetaInflate;
+#if DEBUG
+                       if (inflated.ID > 0)
+                               inflated.ID = -inflated.ID;
+#endif
                        return inflated;
                }
 
+               //
+               // Is this member accessible from invocationType
+               //
+               public bool IsAccessible (TypeSpec invocationType)
+               {
+                       var ma = Modifiers & Modifiers.AccessibilityMask;
+                       if (ma == Modifiers.PUBLIC)
+                               return true;
+
+                       var parentType = /* this as TypeSpec ?? */ DeclaringType;
+               
+                       //
+                       // If only accessible to the current class or children
+                       //
+                       if (ma == Modifiers.PRIVATE)
+                               return invocationType.MemberDefinition == parentType.MemberDefinition ||
+                                       TypeManager.IsNestedChildOf (invocationType, parentType);
+
+                       if ((ma & Modifiers.INTERNAL) != 0) {
+                               var b = TypeManager.IsThisOrFriendAssembly (invocationType == InternalType.FakeInternalType ?
+                                        CodeGen.Assembly.Builder : invocationType.Assembly, Assembly);
+                               if (b || ma == Modifiers.INTERNAL)
+                                       return b;
+                       }
+
+                       // PROTECTED
+                       if (!TypeManager.IsNestedFamilyAccessible (invocationType, parentType))
+                               return false;
+
+                       return true;
+               }
+
                //
                // Returns member CLS compliance based on full member hierarchy
                //
@@ -1283,6 +1325,9 @@ namespace Mono.CSharp {
                
                public bool CheckAccessLevel (TypeSpec check_type)
                {
+// TODO: Use this instead
+//                     return PartialContainer.Definition.IsAccessible (check_type);
+
                        TypeSpec tb = PartialContainer.Definition;
                        check_type = check_type.GetDefinition ();
 
@@ -1337,7 +1382,7 @@ namespace Mono.CSharp {
                                return null;
 
                        // FIXME: Breaks error reporting
-                       if (!CheckAccessLevel (t))
+                       if (!t.IsAccessible (CurrentType))
                                return null;
 
                        return t;