[Mono-bugs] [Bug 42416][Nor] New - mcs cannot cast a struct to an interface type

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
Tue, 6 May 2003 02:32: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 mathpup@mylinuxisp.com.

http://bugzilla.ximian.com/show_bug.cgi?id=42416

--- shadow/42416	Tue May  6 02:32:57 2003
+++ shadow/42416.tmp.19594	Tue May  6 02:32:57 2003
@@ -0,0 +1,71 @@
+Bug#: 42416
+Product: Mono/MCS
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: mathpup@mylinuxisp.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: mcs cannot cast a struct to an interface type
+
+Description of Problem: 
+ 
+According to the ECMA C# spec 18.3.5, an instance of a struct can be cast to an 
+interface type, and in doing so, an implicit boxing operation takes place. In the 
+sample program below, mcs seems to perform the boxing operation, but in doing so, 
+it appears to "forget" that the variable implements the interface. Interesting, 
+inserting an explicit cast object so that the problematic line reads  
+ 
+	IStorable isTemp = (IStorable) (object) theStruct; 
+ 
+allows the program to compile. 
+ 
+Test case: 
+ 
+interface IStorable {} 
+ 
+public struct MyStruct : IStorable {} 
+ 
+public class Tester 
+{ 
+  static void Main() 
+  { 
+    MyStruct theStruct = new MyStruct(); 
+    IStorable isTemp = (IStorable) theStruct; 
+	} 
+} 
+ 
+     
+ 
+ 
+ 
+Steps to reproduce the problem: 
+1. mcs implicit-box.cs 
+ 
+ 
+Actual Results: 
+ 
+implicit-box.cs(10) error CS0029: Cannot convert implicitly from `object' to 
+`IStorable' 
+ 
+ 
+Expected Results: 
+ 
+Successful compilation 
+ 
+ 
+How often does this happen?  
+ 
+Always 
+ 
+Additional Information: 
+ 
+Compiles fine with csc (Rotor).