Author: martin
Date: 2006-01-18 12:38:12 -0500 (Wed, 18 Jan 2006)
New Revision: 55741
Added:
branches/mono-1-1-13/mcs/tests/gtest-236.cs
branches/mono-1-1-13/mcs/tests/gtest-237.cs
branches/mono-1-1-13/mcs/tests/gtest-238-lib.cs
branches/mono-1-1-13/mcs/tests/gtest-238.cs
branches/mono-1-1-13/mcs/tests/gtest-239.cs
Removed:
branches/mono-1-1-13/mcs/errors/gcs0408-2.cs
branches/mono-1-1-13/mcs/errors/gcs0408-3.cs
branches/mono-1-1-13/mcs/errors/gcs0408-4.cs
branches/mono-1-1-13/mcs/errors/gcs0408.cs
Modified:
branches/mono-1-1-13/mcs/gmcs/ChangeLog
branches/mono-1-1-13/mcs/gmcs/class.cs
branches/mono-1-1-13/mcs/gmcs/expression.cs
Log:
**** Merged r55728 from HEAD ****
Deleted: branches/mono-1-1-13/mcs/errors/gcs0408-2.cs
===================================================================
--- branches/mono-1-1-13/mcs/errors/gcs0408-2.cs 2006-01-18 17:34:09 UTC
(rev 55740)
+++ branches/mono-1-1-13/mcs/errors/gcs0408-2.cs 2006-01-18 17:38:12 UTC
(rev 55741)
@@ -1,16 +0,0 @@
-// CS0408: `X<T>' cannot define overload members that may unify for some type
parameter substitutions
-// Line: 9
-class X<T>
-{
- void Foo (T[] t)
- { }
-
- void Foo (int[] t)
- { }
-}
-
-class X
-{
- static void Main ()
- { }
-}
Deleted: branches/mono-1-1-13/mcs/errors/gcs0408-3.cs
===================================================================
--- branches/mono-1-1-13/mcs/errors/gcs0408-3.cs 2006-01-18 17:34:09 UTC
(rev 55740)
+++ branches/mono-1-1-13/mcs/errors/gcs0408-3.cs 2006-01-18 17:38:12 UTC
(rev 55741)
@@ -1,16 +0,0 @@
-// CS0408: `X<T>' cannot define overload members that may unify for some type
parameter substitutions
-// Line: 9
-class X<T>
-{
- void Foo (T[] t)
- { }
-
- void Foo (int[][] t)
- { }
-}
-
-class X
-{
- static void Main ()
- { }
-}
Deleted: branches/mono-1-1-13/mcs/errors/gcs0408-4.cs
===================================================================
--- branches/mono-1-1-13/mcs/errors/gcs0408-4.cs 2006-01-18 17:34:09 UTC
(rev 55740)
+++ branches/mono-1-1-13/mcs/errors/gcs0408-4.cs 2006-01-18 17:38:12 UTC
(rev 55741)
@@ -1,16 +0,0 @@
-// CS0408: `X<T>' cannot define overload members that may unify for some type
parameter substitutions
-// Line: 9
-class X<T>
-{
- void Foo (T t)
- { }
-
- void Foo (int[] t)
- { }
-}
-
-class X
-{
- static void Main ()
- { }
-}
Deleted: branches/mono-1-1-13/mcs/errors/gcs0408.cs
===================================================================
--- branches/mono-1-1-13/mcs/errors/gcs0408.cs 2006-01-18 17:34:09 UTC (rev
55740)
+++ branches/mono-1-1-13/mcs/errors/gcs0408.cs 2006-01-18 17:38:12 UTC (rev
55741)
@@ -1,16 +0,0 @@
-// CS0408: `X<T>' cannot define overload members that may unify for some type
parameter substitutions
-// Line: 9
-class X<T>
-{
- public void Foo (T t)
- { }
-
- public void Foo (int i)
- { }
-}
-
-class X
-{
- static void Main ()
- { }
-}
Modified: branches/mono-1-1-13/mcs/gmcs/ChangeLog
===================================================================
--- branches/mono-1-1-13/mcs/gmcs/ChangeLog 2006-01-18 17:34:09 UTC (rev
55740)
+++ branches/mono-1-1-13/mcs/gmcs/ChangeLog 2006-01-18 17:38:12 UTC (rev
55741)
@@ -1,3 +1,18 @@
+2006-01-18 Martin Baulig <[EMAIL PROTECTED]>
+
+ Fix #76417: a generic class may now have methods which may unify
+ for some type parameter substitutions.
+
+ * class.cs (Method.IsDuplicateImplementation): Don't report CS0408
+ for methods which may unify anymore.
+
+ * expression.cs (Invocation.MoreSpecific): New private static
+ method; checks whether one method is more specific than another
+ according to 14.4.2.2 of the spec.
+ (Invocation.BetterFunction): Implement the tie-breaking rules from
+ 14.4.2.2 of the spec: if two methods unify for some type parameter
+ substitution, we need to pick the more specific one.
+
2006-01-16 Martin Baulig <[EMAIL PROTECTED]>
* generic.cs (ConstraintChecker.CheckConstraint): Fix #77167.
Modified: branches/mono-1-1-13/mcs/gmcs/class.cs
===================================================================
--- branches/mono-1-1-13/mcs/gmcs/class.cs 2006-01-18 17:34:09 UTC (rev
55740)
+++ branches/mono-1-1-13/mcs/gmcs/class.cs 2006-01-18 17:38:12 UTC (rev
55741)
@@ -3776,34 +3776,6 @@
return true;
}
- bool MayUnify (MethodCore first, MethodCore second)
- {
- int a_type_params = 0;
- if (first.GenericMethod != null)
- a_type_params =
first.GenericMethod.CountTypeParameters;
-
- int b_type_params = 0;
- if (second.GenericMethod != null)
- b_type_params =
second.GenericMethod.CountTypeParameters;
-
- if (a_type_params != b_type_params)
- return false;
-
- Type[] class_infered, method_infered;
- if (Parent.CountTypeParameters > 0)
- class_infered = new Type
[Parent.CountTypeParameters];
- else
- class_infered = null;
-
- if (a_type_params > 0)
- method_infered = new Type [a_type_params];
- else
- method_infered = null;
-
- return TypeManager.MayBecomeEqualGenericInstances (
- first.ParameterTypes, second.ParameterTypes,
class_infered, method_infered);
- }
-
protected bool IsDuplicateImplementation (MethodCore method)
{
if (method == this || !(method.MemberName.Equals
(MemberName)))
@@ -3823,7 +3795,6 @@
return false;
bool equal = true;
- bool may_unify = MayUnify (this, method);
for (int i = 0; i < param_types.Length; i++) {
if (param_types [i] != ParameterTypes [i])
@@ -3831,12 +3802,12 @@
}
if (IsExplicitImpl && (method.InterfaceType !=
InterfaceType))
- equal = may_unify = false;
+ equal = false;
// TODO: make operator compatible with MethodCore to
avoid this
if (this is Operator && method is Operator) {
if (MemberType != method.MemberType)
- equal = may_unify = false;
+ equal = false;
}
if (equal) {
@@ -3865,12 +3836,6 @@
Report.Error (111, Location,
TypeContainer.Error111, GetSignatureForError ());
return true;
- } else if (may_unify) {
- Report.Error (408, Location,
- "`{0}' cannot define overload
members that " +
- "may unify for some type
parameter substitutions",
- Parent.MemberName.ToString ());
- return true;
}
return false;
Modified: branches/mono-1-1-13/mcs/gmcs/expression.cs
===================================================================
--- branches/mono-1-1-13/mcs/gmcs/expression.cs 2006-01-18 17:34:09 UTC (rev
55740)
+++ branches/mono-1-1-13/mcs/gmcs/expression.cs 2006-01-18 17:38:12 UTC (rev
55741)
@@ -4292,6 +4292,27 @@
return null;
}
+
+ static int MoreSpecific (EmitContext ec, Type p, Type q,
Location loc)
+ {
+ if (p.IsGenericParameter && !q.IsGenericParameter)
+ return -1;
+ if (!p.IsGenericParameter && q.IsGenericParameter)
+ return 1;
+
+ if (p.IsGenericInstance) {
+ Type[] pargs = TypeManager.GetTypeArguments (p);
+ Type[] qargs = TypeManager.GetTypeArguments (q);
+
+ for (int i = 0; i < pargs.Length; i++) {
+ int better = MoreSpecific (ec, pargs
[i], qargs [i], loc);
+ if (better != 0)
+ return better;
+ }
+ }
+
+ return 0;
+ }
/// <summary>
/// Determines "Better function" between candidate
@@ -4303,12 +4324,12 @@
/// true if candidate is better than the current best match
/// </remarks>
static bool BetterFunction (EmitContext ec, ArrayList args, int
argument_count,
- MethodBase candidate, bool
candidate_params,
- MethodBase best, bool best_params,
Location loc)
+ MethodBase candidate, bool
candidate_params,
+ MethodBase best, bool best_params,
Location loc)
{
ParameterData candidate_pd =
TypeManager.GetParameterData (candidate);
ParameterData best_pd = TypeManager.GetParameterData
(best);
-
+
bool better_at_least_one = false;
bool same = true;
for (int j = 0; j < argument_count; ++j) {
@@ -4356,6 +4377,25 @@
else if (!TypeManager.IsGenericMethod (best) &&
TypeManager.IsGenericMethod (candidate))
return false;
+ MethodBase orig_candidate =
candidate.Mono_IsInflatedMethod ?
+ candidate.GetGenericMethodDefinition () :
candidate;
+ MethodBase orig_best = best.Mono_IsInflatedMethod ?
+ best.GetGenericMethodDefinition () : best;
+
+ ParameterData orig_candidate_pd =
TypeManager.GetParameterData (orig_candidate);
+ ParameterData orig_best_pd =
TypeManager.GetParameterData (orig_best);
+
+ for (int j = 0; j < argument_count; ++j) {
+ Type ct = TypeManager.TypeToCoreType
(orig_candidate_pd.ParameterType (j));
+ Type bt = TypeManager.TypeToCoreType
(orig_best_pd.ParameterType (j));
+
+ int more_specific = MoreSpecific (ec, ct, bt,
loc);
+ if (more_specific > 0)
+ return true;
+ else if (more_specific < 0)
+ return false;
+ }
+
//
// Note that this is not just an optimization. This
handles the case
// This handles the case
Copied: branches/mono-1-1-13/mcs/tests/gtest-236.cs (from rev 55728,
trunk/mcs/tests/gtest-236.cs)
Copied: branches/mono-1-1-13/mcs/tests/gtest-237.cs (from rev 55728,
trunk/mcs/tests/gtest-237.cs)
Copied: branches/mono-1-1-13/mcs/tests/gtest-238-lib.cs (from rev 55728,
trunk/mcs/tests/gtest-238-lib.cs)
Copied: branches/mono-1-1-13/mcs/tests/gtest-238.cs (from rev 55728,
trunk/mcs/tests/gtest-238.cs)
Copied: branches/mono-1-1-13/mcs/tests/gtest-239.cs (from rev 55728,
trunk/mcs/tests/gtest-239.cs)
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches