In gmcs:
authorRaja R Harinath <harinath@hurrynot.org>
Sun, 28 Jan 2007 18:36:33 +0000 (18:36 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Sun, 28 Jan 2007 18:36:33 +0000 (18:36 -0000)
Fix #80534, gtest-309.cs
* generic.cs (UnifyType): Rename from InferType.  Make unification
of generic insts simpler and don't insist on inferring all generic
parameters in a single generic inst unification.
(UnifyTypes): New.
(InferGenericInstance): Remove.
Analysis and initial patch by David Mitchell <dmitchell@logos.com>.

In tests:
* gtest-309.cs: Renamed from errors/gcs0411-3.cs.
* gtest-310.cs: New test from #80534.

In errors:
* gcs0411-3.cs: Rename to tests/gtest-309.cs.

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

1  2 
mcs/errors/ChangeLog
mcs/errors/gcs0411-3.cs
mcs/gmcs/ChangeLog
mcs/gmcs/generic.cs
mcs/tests/ChangeLog
mcs/tests/gtest-309.cs
mcs/tests/gtest-310.cs

index 756c0c584281322eae60d1062dc1ef26bb2ff473,756c0c584281322eae60d1062dc1ef26bb2ff473..577419e0a4e34478af73bdfdefa476c8aa1d5c61
@@@ -1,3 -1,3 +1,7 @@@
++2007-01-28  Raja R Harinath  <rharinath@novell.com>
++
++      * gcs0411-3.cs: Rename to tests/gtest-309.cs.
++
  2006-11-19  Gert Driesen  <drieseng@users.sourceforge.net>
  
        * cs1058.cs: Removed as CS1058 does not apply to 1.0 profile.
diff --cc mcs/errors/gcs0411-3.cs
index bddfb57da99275def1dc5dce1997e351e7f0c0ce,bddfb57da99275def1dc5dce1997e351e7f0c0ce..0000000000000000000000000000000000000000
deleted file mode 100644,100644
+++ /dev/null
@@@ -1,17 -1,17 +1,0 @@@
--// gcs0411.cs: The type arguments for method `Foo' cannot be inferred from the usage. Try specifying the type arguments explicitly
--// Line: 15
--
--class Test<A,B>
--{
--      public void Foo<V,W> (Test<A,W> x, Test<V,B> y)
--      { }
--}
--
--class X
--{
--      static void Main ()
--      {
--              Test<float,int> test = new Test<float,int> ();
--              test.Foo (test, test);
--      }
--}
index 3960735d0e5dc319c2c80e67f3965a1ee8749976,3960735d0e5dc319c2c80e67f3965a1ee8749976..2ff4411b39007f841a2f481c1522552ebb38b65c
@@@ -1,3 -1,3 +1,13 @@@
++2007-01-28  Raja R Harinath  <rharinath@novell.com>
++
++      Fix #80534, gtest-309.cs
++      * generic.cs (UnifyType): Rename from InferType.  Make unification
++      of generic insts simpler and don't insist on inferring all generic
++      parameters in a single generic inst unification.
++      (UnifyTypes): New.
++      (InferGenericInstance): Remove.
++      Analysis and initial patch by David Mitchell <dmitchell@logos.com>.
++
  2007-01-20  Marek Safar  <marek.safar@gmail.com>
  
        * cs-parser.jay: Better parameter error handling.
index 5a81309b45a9fd777247a18ea7b79a1f077db5b8,5a81309b45a9fd777247a18ea7b79a1f077db5b8..ad69957df20d8196ec18c990fd533164084b325d
@@@ -2217,11 -2217,11 +2217,7 @@@ namespace Mono.CSharp 
                        return true;
                }
  
--              //
--              // Type inference.
--              //
--
--              static bool InferType (Type pt, Type at, Type[] inferred)
++              static bool UnifyType (Type pt, Type at, Type[] inferred)
                {
                        if (pt.IsGenericParameter) {
                                if (pt.DeclaringMethod == null)
  
                                int pos = pt.GenericParameterPosition;
  
--                              if (inferred [pos] == null) {
++                              if (inferred [pos] == null)
                                        inferred [pos] = at;
--                                      return true;
--                              }
--
--                              if (inferred [pos] != at)
--                                      return false;
  
--                              return true;
++                              return inferred [pos] == at;
                        }
  
                        if (!pt.ContainsGenericParameters) {
                                if (at.ContainsGenericParameters)
--                                      return InferType (at, pt, inferred);
++                                      return UnifyType (at, pt, inferred);
                                else
                                        return true;
                        }
                                        if (at.GetArrayRank () != pt.GetArrayRank ())
                                                return false;
  
--                                      return InferType (pt.GetElementType (), at.GetElementType (), inferred);
++                                      return UnifyType (pt.GetElementType (), at.GetElementType (), inferred);
                                }
  
                                if (!pt.IsGenericType)
                                        return false;
  
                                Type[] args = GetTypeArguments (pt);
--                              return InferType (args [0], at.GetElementType (), inferred);
++                              return UnifyType (args [0], at.GetElementType (), inferred);
                        }
  
                        if (pt.IsArray) {
                                    (pt.GetArrayRank () != at.GetArrayRank ()))
                                        return false;
  
--                              return InferType (pt.GetElementType (), at.GetElementType (), inferred);
++                              return UnifyType (pt.GetElementType (), at.GetElementType (), inferred);
                        }
  
                        if (pt.IsByRef && at.IsByRef)
--                              return InferType (pt.GetElementType (), at.GetElementType (), inferred);
++                              return UnifyType (pt.GetElementType (), at.GetElementType (), inferred);
                        ArrayList list = new ArrayList ();
                        if (at.IsGenericType)
                                list.Add (at);
  
                        list.AddRange (TypeManager.GetInterfaces (at));
  
--                      bool found_one = false;
--
                        foreach (Type type in list) {
                                if (!type.IsGenericType)
                                        continue;
  
--                              Type[] inferred_types = new Type [inferred.Length];
--
--                              if (!InferGenericInstance (pt, type, inferred_types))
++                              if (DropGenericTypeArguments (pt) != DropGenericTypeArguments (type))
                                        continue;
  
--                              for (int i = 0; i < inferred_types.Length; i++) {
--                                      if (inferred [i] == null) {
--                                              inferred [i] = inferred_types [i];
--                                              continue;
--                                      }
--
--                                      if (inferred [i] != inferred_types [i])
--                                              return false;
--                              }
--
--                              found_one = true;
++                              if (!UnifyTypes (pt.GetGenericArguments (), type.GetGenericArguments (), inferred))
++                                      return false;
                        }
  
--                      return found_one;
++                      return true;
                }
  
--              static bool InferGenericInstance (Type pt, Type at, Type[] inferred_types)
++              static bool UnifyTypes (Type[] pts, Type [] ats, Type [] inferred)
                {
--                      Type[] at_args = at.GetGenericArguments ();
--                      Type[] pt_args = pt.GetGenericArguments ();
--
--                      if (at_args.Length != pt_args.Length)
--                              return false;
--
--                      for (int i = 0; i < at_args.Length; i++) {
--                              if (!InferType (pt_args [i], at_args [i], inferred_types))
++                      for (int i = 0; i < ats.Length; i++) {
++                              if (!UnifyType (pts [i], ats [i], inferred))
                                        return false;
                        }
--
--                      for (int i = 0; i < inferred_types.Length; i++) {
--                              if (inferred_types [i] == null)
--                                      return false;
--                      }
--
                        return true;
                }
  
                                Type pt = pd.ParameterType (i);
                                Type at = a.Type;
  
--                              if (!InferType (pt, at, inferred_types))
++                              if (!UnifyType (pt, at, inferred_types))
                                        return false;
                        }
  
                                if ((a.Expr is NullLiteral) || (a.Expr is MethodGroupExpr))
                                        continue;
  
--                              if (!InferType (element_type, a.Type, inferred_types))
++                              if (!UnifyType (element_type, a.Type, inferred_types))
                                        return false;
                        }
  
                static bool InferTypeArguments (Type[] param_types, Type[] arg_types,
                                                Type[] inferred_types)
                {
--                      if (inferred_types == null)
--                              return false;
--
                        for (int i = 0; i < arg_types.Length; i++) {
                                if (arg_types [i] == null)
                                        continue;
  
--                              if (!InferType (param_types [i], arg_types [i], inferred_types))
++                              if (!UnifyType (param_types [i], arg_types [i], inferred_types))
                                        return false;
                        }
  
index 8e214ad7da9db6b34255aa9bdc98c5f5c5562897,8a0924cdc9bb7a460308fdd97381ecf8e3676adc..9d232e2fdd8613ecc6f4826c5e1504a83aca8321
@@@ -1,11 -1,3 +1,14 @@@
 +2007-01-28  Raja R Harinath  <rharinath@novell.com>
 +
++      * gtest-309.cs: Renamed from errors/gcs0411-3.cs.
++      * gtest-310.cs: New test from #80534.
++
 +      * 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.
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..34aec07b0cfd63069edf5071fb357127d5894283
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,14 @@@
++class Test<A,B>
++{
++      public void Foo<V,W> (Test<A,W> x, Test<V,B> y)
++      { }
++}
++
++class X
++{
++      static void Main ()
++      {
++              Test<float,int> test = new Test<float,int> ();
++              test.Foo (test, test);
++      }
++}
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..b4243ff38cde0ecbdd6c45365e03fb85664600b9
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,19 @@@
++using System;
++using System.Collections.Generic;
++
++namespace MonoBugs
++{
++      public static class IncompleteGenericInference
++      {
++              public static void DoSomethingGeneric<T1, T2>(IEnumerable<T1> t1, IDictionary<T1,T2> t2)
++              {
++              }
++
++              public static void Main()
++              {
++                      List<int> list = new List<int>();
++                      System.Collections.Generic.Dictionary<int, float> dictionary = new Dictionary<int, float>();
++                      DoSomethingGeneric(list, dictionary);
++              }
++      }
++}