2007-11-05 Mark Probst <mark.probst@gmail.com>
authorMark Probst <mark.probst@gmail.com>
Mon, 5 Nov 2007 16:03:42 +0000 (16:03 -0000)
committerMark Probst <mark.probst@gmail.com>
Mon, 5 Nov 2007 16:03:42 +0000 (16:03 -0000)
* Binder.cs: Treat matches with different argument types as
ambiguous, too.  Fixes #324998.

2007-11-05  Mark Probst  <mark.probst@gmail.com>

* BinderTests.cs: Add test for bug #324998.

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

mcs/class/corlib/System.Reflection/Binder.cs
mcs/class/corlib/System.Reflection/ChangeLog
mcs/class/corlib/Test/System.Reflection/BinderTests.cs
mcs/class/corlib/Test/System.Reflection/ChangeLog

index 3ea054c1feb8843176aee8b93a5b73ba71e441d3..323db37245444359d0064149c0a3b702b7c5c00e 100644 (file)
@@ -100,9 +100,33 @@ namespace System.Reflection
 
                        for (int current = 0; current < count; current++) 
                        {
-                               int level = GetDerivedLevel (match[current].DeclaringType);
+                               MethodBase m = match [current];
+                               int level = GetDerivedLevel (m.DeclaringType);
                                if (level == highLevel)
                                        throw new AmbiguousMatchException ();
+                               // If the argument types differ we
+                               // have an ambigous match, as well
+                               if (matchId >= 0) {
+                                       ParameterInfo[] p1 = m.GetParameters ();
+                                       ParameterInfo[] p2 = match [matchId].GetParameters ();
+                                       bool equal = true;
+
+                                       if (p1.Length != p2.Length)
+                                               equal = false;
+                                       else {
+                                               int i;
+
+                                               for (i = 0; i < p1.Length; ++i) {
+                                                       if (p1 [i].ParameterType != p2 [i].ParameterType) {
+                                                               equal = false;
+                                                               break;
+                                                       }
+                                               }
+                                       }
+
+                                       if (!equal)
+                                               throw new AmbiguousMatchException ();
+                               }
 
                                if (level > highLevel) 
                                {
index 8e04ff1d9feb48f196c974466812a250254091de..b55b7eefb4214e8b542c3526c4d60f3a62120bab 100644 (file)
@@ -1,3 +1,8 @@
+2007-11-05  Mark Probst  <mark.probst@gmail.com>
+
+       * Binder.cs: Treat matches with different argument types as
+       ambiguous, too.  Fixes #324998.
+
 2007-11-01  Zoltan Varga  <vargaz@gmail.com>
 
        * Binder.cs: Avoid returning a method with a ParamArray attribute when a normal
index 7d27282d157d078d59c794e0f7fcf9d3ba519a76..229300bb337e5fd6b80a2a51b22ffd29bc436e85 100644 (file)
@@ -409,6 +409,34 @@ namespace MonoTests.System.Reflection
                {
                        public new void Foo (Bug76083ArgBase a) {}
                }
+
+               private const BindingFlags BUG324998_BINDING_FLAGS
+                       = BindingFlags.Public | BindingFlags.NonPublic
+                       | BindingFlags.Instance | BindingFlags.Static
+                       | BindingFlags.IgnoreCase;
+
+               class Bug324998AGood { public virtual void f(int i1, int i2, bool b) {} }
+
+               class Bug324998BGood : Bug324998AGood { public override void f(int i1, int i2, bool b) {} }
+
+               class Bug324998ABad {
+                       public virtual void f(int i1, int i2) {}
+                       public virtual void f(int i1, int i2, bool b) {}
+               }
+
+               class Bug324998BBad : Bug324998ABad { public override void f(int i1, int i2, bool b) {} }
+
+               [Test]
+               public void Bug324998Good () {
+                       if (typeof(Bug324998BGood).GetMethod("f", BUG324998_BINDING_FLAGS) == null)
+                               throw new Exception("Bug324998Good");
+               }
+
+               [Test]
+               [ExpectedException (typeof (AmbiguousMatchException))]
+               public void Bug324998Bad () {
+                       typeof(Bug324998BBad).GetMethod("f", BUG324998_BINDING_FLAGS);
+               }
        }
 }
 
index e8582485e1893ca8bf752fc6516a5909a36c7452..9a2280c71b14165d9bdeb534e9e9c39eb4f092b9 100644 (file)
@@ -1,3 +1,7 @@
+2007-11-05  Mark Probst  <mark.probst@gmail.com>
+
+       * BinderTests.cs: Add test for bug #324998.
+
 2007-11-04  Miguel de Icaza  <miguel@novell.com>
 
        * ParameterInfoTest.cs: Add new test for testing the [Optional]