Author: marek
Date: 2008-01-03 12:32:48 -0500 (Thu, 03 Jan 2008)
New Revision: 92193
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/expression.cs
Log:
2008-01-03 Marek Safar <[EMAIL PROTECTED]>
A fix for bug #351047
* expression.cs (Binary.ResolveOperator): Allow equality operators
between
null and structs only when equality and inequality operators are defined
either as an user-operators or predefined operators.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2008-01-03 17:20:42 UTC (rev 92192)
+++ trunk/mcs/mcs/ChangeLog 2008-01-03 17:32:48 UTC (rev 92193)
@@ -1,6 +1,13 @@
2008-01-03 Marek Safar <[EMAIL PROTECTED]>
A fix for bug #351047
+ * expression.cs (Binary.ResolveOperator): Allow equality operators
between
+ null and structs only when equality and inequality operators are defined
+ either as an user-operators or predefined operators.
+
+2008-01-03 Marek Safar <[EMAIL PROTECTED]>
+
+ A fix for bug #351047
* generic.cs, typemanager.cs, class.cs: New IsReferenceType helper
method.
2008-01-03 Marek Safar <[EMAIL PROTECTED]>
Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2008-01-03 17:20:42 UTC (rev 92192)
+++ trunk/mcs/mcs/expression.cs 2008-01-03 17:32:48 UTC (rev 92193)
@@ -1838,15 +1838,25 @@
}
//
+ // 7.9.9 Equality operators and null
+ //
// CSC 2 has this behavior, it allows
structs to be compared
// with the null literal *outside* of a
generics context and
// inlines that as true or false.
//
// This is, in my opinion, completely
wrong.
//
- if (RootContext.Version !=
LanguageVersion.ISO_1 && l.IsValueType){
+ if (RootContext.Version !=
LanguageVersion.ISO_1 && l.IsValueType) {
+ if
(!TypeManager.IsPrimitiveType (l) && !TypeManager.IsEnumType (l)) {
+ if (MemberLookup
(ec.ContainerType, l, oper_names [(int)Operator.Equality], MemberTypes.Method,
AllBindingFlags, loc) == null &&
+ MemberLookup
(ec.ContainerType, l, oper_names [(int)Operator.Inequality],
MemberTypes.Method, AllBindingFlags, loc) == null) {
+
Error_OperatorCannotBeApplied ();
+ return null;
+ }
+ }
+
Warning_Constant_Result (loc,
oper == Operator.Inequality, l);
- return new BoolLiteral (oper ==
Operator.Inequality, loc);
+ return new BoolConstant (oper
== Operator.Inequality, loc);
}
}
@@ -1863,6 +1873,8 @@
}
//
+ // 7.9.9 Equality operators and null
+ //
// CSC 2 has this behavior, it allows
structs to be compared
// with the null literal *outside* of a
generics context and
// inlines that as true or false.
@@ -1870,8 +1882,16 @@
// This is, in my opinion, completely
wrong.
//
if (RootContext.Version !=
LanguageVersion.ISO_1 && r.IsValueType){
+ if
(!TypeManager.IsPrimitiveType (r) && !TypeManager.IsEnumType (r)) {
+ if (MemberLookup
(ec.ContainerType, r, oper_names [(int) Operator.Equality], MemberTypes.Method,
AllBindingFlags, loc) == null &&
+ MemberLookup
(ec.ContainerType, r, oper_names [(int) Operator.Inequality],
MemberTypes.Method, AllBindingFlags, loc) == null) {
+
Error_OperatorCannotBeApplied ();
+ return null;
+ }
+ }
+
Warning_Constant_Result (loc,
oper == Operator.Inequality, r);
- return new BoolLiteral (oper ==
Operator.Inequality, loc);
+ return new BoolConstant (oper
== Operator.Inequality, loc);
}
}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches