2004-11-10 Martin Baulig <martin@localhost>
authorMartin Baulig <martin@novell.com>
Tue, 9 Nov 2004 23:13:17 +0000 (23:13 -0000)
committerMartin Baulig <martin@novell.com>
Tue, 9 Nov 2004 23:13:17 +0000 (23:13 -0000)
* typemanager.cs
(TypeManager.IsPrivateAccessible): New public method.
(Closure.Filter): Use IsPrivateAccessible() instead of IsEqual().

svn path=/trunk/mcs/; revision=35926

mcs/gmcs/ChangeLog
mcs/gmcs/typemanager.cs

index 64a1c20af6a55d5085f84d5c3e2aca6515cc982c..33e07f32624e0f05ad64fb142a2e4f3c643699c2 100755 (executable)
@@ -1,3 +1,9 @@
+2004-11-10  Martin Baulig  <martin@localhost>
+
+       * typemanager.cs
+       (TypeManager.IsPrivateAccessible): New public method.
+       (Closure.Filter): Use IsPrivateAccessible() instead of IsEqual().
+
 2004-11-10  Martin Baulig  <martin@ximian.com>
 
        * class.cs (TypeContainer.DefineType): Call
index 3048d8dd4eb4d9cd2f71f9611a396ee6b5679c21..7e08cc98e869e2dc961c620cfd63933cef7e337e 100755 (executable)
@@ -1946,6 +1946,48 @@ public class TypeManager {
                return false;
        }
 
+       public static bool IsPrivateAccessible (Type type, Type parent)
+       {
+               if (type.Equals (parent))
+                       return true;
+
+               if ((type is TypeBuilder) && type.IsGenericTypeDefinition && parent.IsGenericInstance) {
+                       //
+                       // `a' is a generic type definition's TypeBuilder and `b' is a
+                       // generic instance of the same type.
+                       //
+                       // Example:
+                       //
+                       // class Stack<T>
+                       // {
+                       //     void Test (Stack<T> stack) { }
+                       // }
+                       //
+                       // The first argument of `Test' will be the generic instance
+                       // "Stack<!0>" - which is the same type than the "Stack" TypeBuilder.
+                       //
+                       //
+                       // We hit this via Closure.Filter() for gen-82.cs.
+                       //
+                       if (type != parent.GetGenericTypeDefinition ())
+                               return false;
+
+                       return true;
+               }
+
+               if (type.IsGenericInstance && parent.IsGenericInstance) {
+                       Type tdef = type.GetGenericTypeDefinition ();
+                       Type pdef = parent.GetGenericTypeDefinition ();
+
+                       if (type.GetGenericTypeDefinition () != parent.GetGenericTypeDefinition ())
+                               return false;
+
+                       return true;
+               }
+
+               return false;
+       }
+
        public static bool IsFamilyAccessible (Type type, Type parent)
        {
                TypeParameter tparam = LookupTypeParameter (type);
@@ -2834,7 +2876,7 @@ public class TypeManager {
 
                        if (ma == MethodAttributes.Private)
                                return private_ok ||
-                                       IsEqual (invocation_type, mb.DeclaringType) ||
+                                       IsPrivateAccessible (invocation_type, mb.DeclaringType) ||
                                        IsNestedChildOf (invocation_type, mb.DeclaringType);
 
                        //
@@ -2885,7 +2927,7 @@ public class TypeManager {
 
                        if (fa == FieldAttributes.Private)
                                return private_ok ||
-                                       IsEqual (invocation_type, fi.DeclaringType) ||
+                                       IsPrivateAccessible (invocation_type, fi.DeclaringType) ||
                                        IsNestedChildOf (invocation_type, fi.DeclaringType);
 
                        //
@@ -2946,7 +2988,7 @@ public class TypeManager {
 
                        if (((qualifier_type == null) || (qualifier_type == invocation_type)) &&
                            (invocation_type != null) &&
-                           IsEqual (m.DeclaringType, invocation_type))
+                           IsPrivateAccessible (m.DeclaringType, invocation_type))
                                return true;
 
                        //