Author: marek
Date: 2006-11-17 18:11:36 -0500 (Fri, 17 Nov 2006)
New Revision: 68113
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/class.cs
trunk/mcs/mcs/convert.cs
trunk/mcs/mcs/ecore.cs
trunk/mcs/mcs/expression.cs
Log:
2006-11-17 Marek Safar <[EMAIL PROTECTED]>
A fix for bug #79941
* class.cs (MemberCore.IsDuplicateImplementation): Add more tricks for
operators.
(Operator.Define): Implicit/Explicit operator of same type is duplicate
even if internal name is different.
* convert.cs (GetConversionOperator): Replaced EmitContext with
parentType.
(UserDefinedConversion): Simplified as the operators cannot be internal.
* ecore.cs (Error_ValueCannotBeConverted): Take account of user
conversions.
(MethodLookup): Replaced EmitContext with parentType.
* expression.cs: Updated.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2006-11-17 23:02:51 UTC (rev 68112)
+++ trunk/mcs/mcs/ChangeLog 2006-11-17 23:11:36 UTC (rev 68113)
@@ -1,3 +1,17 @@
+2006-11-17 Marek Safar <[EMAIL PROTECTED]>
+
+ A fix for bug #79941
+ * class.cs (MemberCore.IsDuplicateImplementation): Add more tricks for
+ operators.
+ (Operator.Define): Implicit/Explicit operator of same type is duplicate
+ even if internal name is different.
+ * convert.cs (GetConversionOperator): Replaced EmitContext with
parentType.
+ (UserDefinedConversion): Simplified as the operators cannot be internal.
+ * ecore.cs (Error_ValueCannotBeConverted): Take account of user
+ conversions.
+ (MethodLookup): Replaced EmitContext with parentType.
+ * expression.cs: Updated.
+
2006-11-09 Raja R Harinath <[EMAIL PROTECTED]>
* driver.cs (BadAssembly): Handle all the ugliness of
Modified: trunk/mcs/mcs/class.cs
===================================================================
--- trunk/mcs/mcs/class.cs 2006-11-17 23:02:51 UTC (rev 68112)
+++ trunk/mcs/mcs/class.cs 2006-11-17 23:11:36 UTC (rev 68113)
@@ -3654,11 +3654,29 @@
return true;
}
+ // TODO: create a special method for operators only to make
code better
protected bool IsDuplicateImplementation (MethodCore method)
{
- if (method == this || !(method.MemberName.Equals
(MemberName)))
+ if (method == this)
return false;
+ Operator op2 = null;
+ Operator op1 = null;
+
+ if (!(method.MemberName.Equals (MemberName)))
+ {
+ op1 = this as Operator;
+ if (op1 == null || !(op1.OperatorType ==
Operator.OpType.Explicit || op1.OperatorType == Operator.OpType.Implicit))
+ return false;
+
+ op2 = method as Operator;
+ if (op2 == null || !(op2.OperatorType ==
Operator.OpType.Explicit || op2.OperatorType == Operator.OpType.Implicit))
+ return false;
+ } else {
+ op1 = this as Operator;
+ op2 = method as Operator;
+ }
+
Type[] param_types = method.ParameterTypes;
// This never happen. Rewrite this as Equal
if (param_types == null && ParameterTypes == null)
@@ -3683,7 +3701,7 @@
equal = false;
// TODO: make operator compatible with MethodCore to
avoid this
- if (this is Operator && method is Operator) {
+ if (op1 != null && op2 != null) {
if (MemberType != method.MemberType)
equal = false;
}
@@ -7707,6 +7725,10 @@
return false;
}
+ // imlicit and explicit operator of same types are not
allowed
+ if (OperatorType == OpType.Explicit || OperatorType ==
OpType.Implicit)
+ MarkForDuplicationCheck ();
+
if (!base.Define ())
return false;
Modified: trunk/mcs/mcs/convert.cs
===================================================================
--- trunk/mcs/mcs/convert.cs 2006-11-17 23:02:51 UTC (rev 68112)
+++ trunk/mcs/mcs/convert.cs 2006-11-17 23:11:36 UTC (rev 68113)
@@ -1109,7 +1109,7 @@
/// Compute the user-defined conversion operator from
source_type to target_type.
/// `look_for_explicit' controls whether we should also
include the list of explicit operators
/// </summary>
- static MethodInfo GetConversionOperator (EmitContext ec,
Expression source, Type target_type, bool look_for_explicit)
+ static MethodInfo GetConversionOperator (Type container_type,
Expression source, Type target_type, bool look_for_explicit)
{
ArrayList ops = new ArrayList (4);
@@ -1117,21 +1117,21 @@
if (source_type != TypeManager.decimal_type) {
AddConversionOperators (ops, source,
target_type, look_for_explicit,
- Expression.MethodLookup (ec,
source_type, "op_Implicit", Location.Null) as MethodGroupExpr);
+ Expression.MethodLookup
(container_type, source_type, "op_Implicit", Location.Null) as MethodGroupExpr);
if (look_for_explicit) {
AddConversionOperators (ops, source,
target_type, look_for_explicit,
Expression.MethodLookup (
- ec, source_type,
"op_Explicit", Location.Null) as MethodGroupExpr);
+ container_type,
source_type, "op_Explicit", Location.Null) as MethodGroupExpr);
}
}
if (target_type != TypeManager.decimal_type) {
AddConversionOperators (ops, source,
target_type, look_for_explicit,
- Expression.MethodLookup (ec,
target_type, "op_Implicit", Location.Null) as MethodGroupExpr);
+ Expression.MethodLookup
(container_type, target_type, "op_Implicit", Location.Null) as MethodGroupExpr);
if (look_for_explicit) {
AddConversionOperators (ops, source,
target_type, look_for_explicit,
Expression.MethodLookup (
- ec, target_type,
"op_Explicit", Location.Null) as MethodGroupExpr);
+ container_type,
target_type, "op_Explicit", Location.Null) as MethodGroupExpr);
}
}
@@ -1181,7 +1181,7 @@
if (!(source is Constant) && hash.Lookup (source_type,
target, out o)) {
method = (MethodInfo) o;
} else {
- method = GetConversionOperator (ec, source,
target, look_for_explicit);
+ method = GetConversionOperator (null, source,
target, look_for_explicit);
if (!(source is Constant))
hash.Insert (source_type, target,
method);
}
Modified: trunk/mcs/mcs/ecore.cs
===================================================================
--- trunk/mcs/mcs/ecore.cs 2006-11-17 23:02:51 UTC (rev 68112)
+++ trunk/mcs/mcs/ecore.cs 2006-11-17 23:11:36 UTC (rev 68113)
@@ -332,7 +332,8 @@
Expression e = (this is EnumConstant) ?
((EnumConstant)this).Child : this;
bool b = Convert.ExplicitNumericConversion (e, target)
!= null;
- if (b || Convert.ExplicitReferenceConversionExists
(Type, target) || Convert.ExplicitUnsafe (e, target) != null) {
+ if (b || Convert.ExplicitReferenceConversionExists
(Type, target) ||
+ Convert.ExplicitUnsafe (e, target) != null ||
Convert.UserDefinedConversion (null, this, target, Location.Null, true) !=
null) {
Report.Error (266, loc, "Cannot implicitly
convert type `{0}' to `{1}'. An explicit conversion exists (are you missing a
cast?)",
TypeManager.CSharpName (Type),
TypeManager.CSharpName (target));
return;
@@ -751,10 +752,10 @@
name, AllMemberTypes,
AllBindingFlags, loc);
}
- public static Expression MethodLookup (EmitContext ec, Type
queried_type,
+ public static Expression MethodLookup (Type container_type,
Type queried_type,
string name, Location
loc)
{
- return MemberLookup (ec.ContainerType, null,
queried_type, name,
+ return MemberLookup (container_type, null,
queried_type, name,
MemberTypes.Method,
AllBindingFlags, loc);
}
@@ -906,7 +907,7 @@
return new Nullable.OperatorTrueOrFalse (e,
is_true, loc).Resolve (ec);
#endif
- operator_group = MethodLookup (ec, e.Type, is_true ?
"op_True" : "op_False", loc);
+ operator_group = MethodLookup (ec.ContainerType,
e.Type, is_true ? "op_True" : "op_False", loc);
if (operator_group == null)
return null;
Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2006-11-17 23:02:51 UTC (rev 68112)
+++ trunk/mcs/mcs/expression.cs 2006-11-17 23:11:36 UTC (rev 68113)
@@ -3052,7 +3052,7 @@
MethodInfo method;
Expression operator_group;
- operator_group = MethodLookup (ec, type, is_and ?
"op_BitwiseAnd" : "op_BitwiseOr", loc);
+ operator_group = MethodLookup (ec.ContainerType, type,
is_and ? "op_BitwiseAnd" : "op_BitwiseOr", loc);
if (operator_group == null) {
Error19 ();
return null;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches