In mcs:
authorRaja R Harinath <harinath@hurrynot.org>
Sun, 28 Jan 2007 11:27:23 +0000 (11:27 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Sun, 28 Jan 2007 11:27:23 +0000 (11:27 -0000)
Fix #80531
* anonymous.cs (ScopeInfo.InflateParameters): New.
(AnonymousContainer.Resolve): Use it to redirect types of
delegate parameters.

In tests:
* gtest-308.cs: New test based on #80531.
* gtest-307.cs: New test based on #80358.

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

mcs/mcs/ChangeLog
mcs/mcs/anonymous.cs
mcs/tests/ChangeLog
mcs/tests/gtest-307.cs [new file with mode: 0644]
mcs/tests/gtest-308.cs [new file with mode: 0644]

index d106bbcfa8abbbb597ebc5899131da3660a775e1..5dce143426cf8fa778976f496de09d0244089e90 100644 (file)
@@ -1,3 +1,10 @@
+2007-01-28  Raja R Harinath  <rharinath@novell.com>
+
+       Fix #80531
+       * anonymous.cs (ScopeInfo.InflateParameters): New.
+       (AnonymousContainer.Resolve): Use it to redirect types of
+       delegate parameters.
+
 2007-01-27  Raja R Harinath  <rharinath@novell.com>
 
        Fix #80530
index e4e68f01d0a68972e775caf81c21c933fcdfc181..3e5601598a8004da55bf9b8b86454814da06e9d9 100644 (file)
@@ -100,6 +100,27 @@ namespace Mono.CSharp {
                        get { return generic_method; }
                }
 
+               public Parameters InflateParameters (Parameters ps)
+               {
+                       if (generic_method == null)
+                               return ps;
+
+                       int n = ps.Count;
+                       if (n == 0)
+                               return ps;
+
+                       Parameter[] inflated_params = new Parameter [n];
+                       Type[] inflated_types = new Type [n];
+
+                       for (int i = 0; i < n; ++i) {
+                               Parameter p = ps [i];
+                               Type it = InflateType (p.ExternalType ()).ResolveAsTypeTerminal (this, false).Type;
+                               inflated_types [i] = it;
+                               inflated_params [i] = new Parameter (it, p.Name, p.ModFlags, p.OptAttributes, p.Location);
+                       }
+                       return new Parameters (inflated_params, inflated_types);
+               }
+
                public TypeExpr InflateType (Type it)
                {
 #if GMCS_SOURCE
@@ -1302,8 +1323,7 @@ namespace Mono.CSharp {
        {
                public readonly Location Location;
 
-               // An array list of AnonymousMethodParameter or null
-               public readonly Parameters Parameters;
+               public Parameters Parameters;
 
                //
                // The block that makes up the body for the anonymous mehtod
@@ -1380,6 +1400,9 @@ namespace Mono.CSharp {
                                ReturnType = return_type_expr.Type;
                        }
 
+                       if (RootScope != null)
+                               Parameters = RootScope.InflateParameters (Parameters);
+
                        aec = new EmitContext (
                                ec.ResolveContext, ec.TypeContainer,
                                RootScope != null ? RootScope : Host, Location, null, ReturnType,
index 8a0924cdc9bb7a460308fdd97381ecf8e3676adc..8e214ad7da9db6b34255aa9bdc98c5f5c5562897 100644 (file)
@@ -1,3 +1,11 @@
+2007-01-28  Raja R Harinath  <rharinath@novell.com>
+
+       * gtest-308.cs: New test based on #80531.
+
+2007-01-27  Raja R Harinath  <rharinath@novell.com>
+
+       * gtest-307.cs: New test based on #80358.
+
 2007-01-11  Raja R Harinath  <rharinath@novell.com>
 
        * gtest-302.cs: New test based on #80249.
diff --git a/mcs/tests/gtest-307.cs b/mcs/tests/gtest-307.cs
new file mode 100644 (file)
index 0000000..86bc1fd
--- /dev/null
@@ -0,0 +1,13 @@
+partial class Foo<T> {}
+partial class Foo<T> {
+       public delegate int F ();
+}
+
+class Bar {
+       static int g () { return 0; }
+       static int Main ()
+       {
+               Foo<int>.F f = g;
+               return f ();
+       }
+}
diff --git a/mcs/tests/gtest-308.cs b/mcs/tests/gtest-308.cs
new file mode 100644 (file)
index 0000000..ce8ffec
--- /dev/null
@@ -0,0 +1,38 @@
+using System;
+
+public class Test {
+       public static Comparison<U> WrapComparison<U>(Comparison<U> comparison)
+       {
+               return delegate(U x, U y) { return comparison(x, y); };
+       }
+
+       public delegate int MyComparison<V> (V x, V y);
+       public static MyComparison<W> WrapMyComparison<W>(MyComparison<W> myComparison)
+       {
+               return delegate(W x, W y) { return myComparison(x, y); };
+       }
+}
+
+public class Foo {
+       static int compare (int x, int y)
+       { return x - y; }
+       static int compare (string x, string y)
+       { return string.Compare (x, y); }
+       static void test (int i)
+       {
+               if (i != 0)
+                       throw new Exception (""+i);
+       }
+       static void Main ()
+       {
+               Comparison<int> ci = Test.WrapComparison<int> (compare);
+               Comparison<string> cs = Test.WrapComparison<string> (compare);
+               Test.MyComparison<int> mci = Test.WrapMyComparison<int> (compare);
+               Test.MyComparison<string> mcs = Test.WrapMyComparison<string> (compare);
+               test (ci (1,1));
+               test (cs ("h", "h"));
+               test (mci (2,2));
+               test (mcs ("g", "g"));
+       }
+}
+