[Mono-bugs] [Bug 74885][Nor] New - ECMA 14.9.6 violation
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Mon, 9 May 2005 14:53:57 -0400 (EDT)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by robertj@gmx.net.
http://bugzilla.ximian.com/show_bug.cgi?id=74885
--- shadow/74885 2005-05-09 14:53:57.000000000 -0400
+++ shadow/74885.tmp.7538 2005-05-09 14:53:57.000000000 -0400
@@ -0,0 +1,78 @@
+Bug#: 74885
+Product: Mono: Compilers
+Version: 1.1
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: C#
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: robertj@gmx.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Summary: ECMA 14.9.6 violation
+
+ECMA 14.9.6 states that the predefined operator "=="
+must fail on value types. Both mcs and gmcs (from SVN)
+violate the rule when a user-defined implicit convertion
+for a numeric type is implemented by a value type:
+
+using System;
+
+struct S {
+ int v;
+
+ public S(int i) {
+ this.v = i;
+ }
+
+ public static implicit operator int(S s) {
+ return s.v;
+ }
+}
+
+class T {
+ static void Main() {
+ S a = new S(1);
+ S b = new S(1);
+ // should fail with error CS0019
+ Console.WriteLine(a == b);
+ }
+}
+
+
+I guess that the problem can be find in [g]mcs/expression.cs,
+method Binary.ResolveOperator(), that doesn't handle the case
+(l.IsValueType && r.IsValueType).
+Therefore the DoNumericPromotions()-call from ResolveOperator()
+promotes the operands to Int32 and the "=="-operator succeeds.
+
+Note that MSFT's CSC 1.0 & 1.1 have the same glitch!
+
+Beside the problem with the user-defined implicit convertion
+for numeric types, CSC 2.0b2 gets fooled by a user-defined
+string convertion as well:
+
+struct S {
+ int v;
+
+ public S(int i) {
+ this.v = i;
+ }
+
+ public static implicit operator string(S s) {
+ return s.v.ToString();
+ }
+}
+
+class T {
+ static void Main() {
+ S a = new S(1);
+ S b = new S(1);
+ // should fail with error CS0019
+ Console.WriteLine(a == b);
+ }
+}