[Mono-bugs] [Bug 54928][Cos] New - implicit operator cannot convert from struct to decimal
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Fri, 27 Feb 2004 08:19:55 -0500 (EST)
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 yoonkit@yahoo.com.
http://bugzilla.ximian.com/show_bug.cgi?id=54928
--- shadow/54928 2004-02-27 08:19:55.000000000 -0500
+++ shadow/54928.tmp.6764 2004-02-27 08:19:55.000000000 -0500
@@ -0,0 +1,73 @@
+Bug#: 54928
+Product: Mono/Compilers
+Version: unspecified
+OS:
+OS Details: Win2K
+Status: NEW
+Resolution:
+Severity:
+Priority: Cosmetic
+Component: C#
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: yoonkit@yahoo.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: implicit operator cannot convert from struct to decimal
+
+==== Description of Problem:
+Error during compilation when using implicit operators,
+especially with long -> decimal.
+
+==== Steps to reproduce the problem:
+
+ public struct ObjectID
+ {
+ private long _l;
+
+ public ObjectID( long l )
+ { _l = l; }
+
+ public static implicit operator long( ObjectID p )
+ { return p._l; }
+
+ public static implicit operator ObjectID( long l )
+ { return new ObjectID( l ); }
+ }
+
+1. Make a struct which has a base type of long integer
+ private long _l;
+2. have a implicit operator
+ public static implicit operator long( ObjectID p ) { return p._l; }
+3. use this struct and set it to a decimal variable.
+ ObjectID vID = 45;
+ decimal vDec = 34;
+ vDec = vID; // <--- error here during compilation.
+
+
+==== Actual Results:
+compile this with mcs, and it will give an error like:
+TestFrm.cs(371) error CS0029: Cannot convert implicitly from 'ObjectID' to
+`decimal'
+
+
+==== Expected Results:
+With csc this compiles without a problem.
+
+==== How often does this happen?
+All the time, during compilation
+
+==== Additional Information:
+
+I can do a work-around, by typecasting it to a long, ie.
+ vDec = (long) vID;
+
+This compiles OK.
+
+I havent tried for other datatypes...
+e.g. int -> decimal, double -> decimal, etc.
+
+Regards,
+
+Yoon Kit.