Author: martin
Date: 2006-03-12 14:59:55 -0500 (Sun, 12 Mar 2006)
New Revision: 57879

Added:
   trunk/mcs/tests/gtest-255.cs
Modified:
   trunk/mcs/gmcs/ChangeLog
   trunk/mcs/gmcs/typemanager.cs
Log:
2006-03-09  Martin Baulig  <[EMAIL PROTECTED]>

        * generic.cs (ConstraintChecker.HasDefaultConstructor): Call
        TypeManager.DropGenericTypeArguments() on the `atype'; fixes #77548.



Modified: trunk/mcs/gmcs/ChangeLog
===================================================================
--- trunk/mcs/gmcs/ChangeLog    2006-03-12 18:35:04 UTC (rev 57878)
+++ trunk/mcs/gmcs/ChangeLog    2006-03-12 19:59:55 UTC (rev 57879)
@@ -1,3 +1,9 @@
+2006-03-12  Martin Baulig  <[EMAIL PROTECTED]>
+
+       * typemanager.cs (TypeManager.ArrayContainsMethod): Use a new
+       private IsSignatureEqual() to compare types; see the comment in
+       that method; fixes #77674.
+
 2006-03-10  Raja R Harinath  <[EMAIL PROTECTED]>
 
        * ecore.cs (Expression.ResolveAsTypeStep): Remove 1-argument wrapper.

Modified: trunk/mcs/gmcs/typemanager.cs
===================================================================
--- trunk/mcs/gmcs/typemanager.cs       2006-03-12 18:35:04 UTC (rev 57878)
+++ trunk/mcs/gmcs/typemanager.cs       2006-03-12 19:59:55 UTC (rev 57879)
@@ -2383,6 +2383,67 @@
                return (LocalBuilder) declare_local_method.Invoke (ig, new 
object [] { t, true });
        }
 
+       private static bool IsSignatureEqual (Type a, Type b)
+       {
+               ///
+               /// Consider the following example (bug #77674):
+               ///
+               ///     public abstract class A
+               ///     {
+               ///        public abstract T Foo<T> ();
+               ///     }
+               ///
+               ///     public abstract class B : A
+               ///     {
+               ///        public override U Foo<T> ()
+               ///        { return default (U); }
+               ///     }
+               ///
+               /// Here, `T' and `U' are method type parameters from different 
methods
+               /// (A.Foo and B.Foo), so both `==' and Equals() will fail.
+               ///
+               /// However, since we're determining whether B.Foo() overrides 
A.Foo(),
+               /// we need to do a signature based comparision and consider 
them equal.
+
+               if (a == b)
+                       return true;
+
+               if (a.IsGenericParameter && b.IsGenericParameter &&
+                   (a.DeclaringMethod != null) && (b.DeclaringMethod != null)) 
{
+                       return a.GenericParameterPosition == 
b.GenericParameterPosition;
+               }
+
+               if (a.IsArray && b.IsArray) {
+                       if (a.GetArrayRank () != b.GetArrayRank ())
+                               return false;
+
+                       return IsSignatureEqual (a.GetElementType (), 
b.GetElementType ());
+               }
+
+               if (a.IsByRef && b.IsByRef)
+                       return IsSignatureEqual (a.GetElementType (), 
b.GetElementType ());
+
+               if (a.IsGenericType && b.IsGenericType) {
+                       if (a.GetGenericTypeDefinition () != 
b.GetGenericTypeDefinition ())
+                               return false;
+
+                       Type[] aargs = a.GetGenericArguments ();
+                       Type[] bargs = b.GetGenericArguments ();
+
+                       if (aargs.Length != bargs.Length)
+                               return false;
+
+                       for (int i = 0; i < aargs.Length; i++) {
+                               if (!IsSignatureEqual (aargs [i], bargs [i]))
+                                       return false;
+                       }
+
+                       return true;
+               }
+
+               return false;
+       }
+
        //
        // Returns whether the array of memberinfos contains the given method
        //
@@ -2395,7 +2456,8 @@
                                continue;
 
                         if (method is MethodInfo && new_method is MethodInfo)
-                                if (((MethodInfo) method).ReturnType != 
((MethodInfo) new_method).ReturnType)
+                                if (!IsSignatureEqual (((MethodInfo) 
method).ReturnType,
+                                                      ((MethodInfo) 
new_method).ReturnType))
                                         continue;
 
                         
@@ -2407,7 +2469,7 @@
                                continue;
                        
                        for (i = 0; i < old_count; i++){
-                               if (old_args [i] != new_args [i])
+                               if (!IsSignatureEqual (old_args [i], new_args 
[i]))
                                        break;
                        }
                        if (i != old_count)

Added: trunk/mcs/tests/gtest-255.cs
===================================================================
--- trunk/mcs/tests/gtest-255.cs        2006-03-12 18:35:04 UTC (rev 57878)
+++ trunk/mcs/tests/gtest-255.cs        2006-03-12 19:59:55 UTC (rev 57879)
@@ -0,0 +1,20 @@
+using System;
+
+public abstract class A
+{
+        public abstract T Foo<T> ();
+}
+
+public abstract class B : A
+{
+        public override T Foo<T> ()
+        {
+                return default (T);
+        }
+}
+
+public class C : B
+{
+       static void Main ()
+       { }
+}


Property changes on: trunk/mcs/tests/gtest-255.cs
___________________________________________________________________
Name: svn:executable
   + *

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to